Include Libray

I have questions about libraries.

(1) Does sketch file contain library files?
(2) If No, then How can i save/attache included libraries with sketch?

I want to save my sketch file with all library.

You can copy the library files .h / .cpp into the same folder as the sketch ( .ino ).
However, you have to change the #include statements in the sketch, replacing the chevrons (<>) with double quotes(")
Do any such copying when the sketch is NOT open in the IDE.

Another option, is to put the libraries under the "src" subfolder of the sketch folder:

You'll need to point the #include directives in the sketch to point to the appropriate location. For example, if your sketch folder structure looked like this:

|_ SomeSketch.ino
|_ src
|_ SomeLibrary
|_ src
|_ SomeLibrary.h
|_ etc...

Then you would change the #include directive in the sketch from:

#include <SomeLibrary.h>


#include "src/SomeLibrary/src/SomeLibrary.h"

The advantage of this over putting the library files directly into the sketch root folder is that it allows you to keep libraries compartmentalized into separate folders. It also avoids the library source files being shown in the Arduino IDE as tabs of your sketch, which might be confusing to some (but also convenient to those who want to experiment with changes to the library.

Once caveat is that the src subfolder is not supported by Arduino Web Editor and there is a bug in the Arduino IDE's "Save as..." in how it is handled:

Does any method that copy library files to sketch folder automatically while compile or save?

None that I'm aware of, and certainly nothing officially provided by Arduino.

You might find some interesting information here: