Xcopy is a powerful and fast copy tool:

most common switches:

  • /E option causes to copy empty sub directories to the destination folder.
  • /H option the the command would also copy hidden and system files to the destination folder.
  • /I  It would not copy files from sub directories. Adding /I switch will avoid the question to the user ‘Does the destination directory specify a file name or directory name on the target‘.
  • /Y Suppress the prompt,  so that you will not be prompted for confirmation for overwriting the file
Xcopy – Exclude files

If you want to copy a directory to another location but want to exclude some files then you can use /EXCLUDE switch with Xcopy command.  You need to put the list of the files to be excluded in a file and then specify this file with the /EXCLUDE switch.

Xcopy /I Sourcedir  Destdir /EXCLUDE:filename

Example:
Copy the directory D:\docs to E:\newdocs\ excluding all pdf and mp3 files:

C:\>notepad 1.txt
\System Volume Information\
\Recycle Bin\
.pdf
.mp3
C:\>Xcopy D:\docs E:\newdocs /EXCLUDE:1.txt
Work with Archive

 

If you want to copy only the files that have archive attribute set, you can use /A and /M switches. Archive attribute indicates whether the file has been modified since the time the attribute was reset.
The command for this is:

Xcopy /A /I /S source_directory destination_directory.

The above command keeps the archive attribute set; It does not reset the attribute.

If you want to reset the archive attribute, you can use /M switch instead of /A. The command for this case would be:

Xcopy /M /I /S source_directory  destination_directory