A few words of thanks would be greatly appreciated.

Creating a Batch File to copy a directory


I have a directory / folder on my desktop and sub-directories / sub-folders in it and various files in various directories. At the end of the day i want to copy those folders and files accordingly to flash drive lets say f: (f drive).

I would like to create a batch file which copies my folders and files as it is as the original ones with same paths. The batch file should be such as that it should only copy those files or folders which are changed and rest should remain same. no need to copy the whole directory again and again.


Hey, they're called switches - they're extra parameters that make the command do a more specific and targeted job (given what the above switches for this command mean below)

/D:m-d-y Copies files that were changed on or after the specified date. If no date, copies only those files whose source time is newer than the destination time. (His suggestion contains no date so all files in that directory - and sub directories (even if empty 'cause of /E) are copied over if newer than the versions in the place they're being copied to.)
/E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.
/C Continues copying even if errors occur.
/R Overwrites read-only files.
/I If destination doesn't exist and copying more than one file, assumes that destination must be a directory.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/Y Suppresses prompting to confirm you want to overwrite.

Here is what i use to copy all my user documents over to a destination drive in XP and Vista...

XCOPY "C:Users" "K:My Vista Backup" /D /E /C /R /I /K /Y

XCOPY "C:DOCUME~1" "I:My XP Backup" /D /E /C /R /I /K /Y

Windows Vista has tried to replace this with Robocopy (Robust File Copy for Windows), but xcopy will still work :)


Thanks to Jake and Luke for this tip on the forum.

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.


This document, titled « Creating a Batch File to copy a directory », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).