Creating a Batch File to copy a directory

 BB -

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 shoud only copy those files or folders which are changed and rest should remain same. no need to copy the whole directory again and again.....

Can u please give me the commands for the said.

Waiting for your replies....

8 replies

try XCOPY with parameter /S or /E


XCOPY C:\Temp C:\Temp2 /S
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

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

works like a charm

What are the /D /E /C /R /I /K /Y for, are they variables that should be input like are they specific dates/years/time a day or something else that is specific to the materiel you are trying to copy or are they just some standards you have to type in the batch file, like are they commands? hope to get an answer soon though I know it is long ago you provided this answer
> the batcher(learner)
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 changed on or after the specified date. If no date is given, 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 does not 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.

Windows Vista has tried to replace this with Robocopy (Robust File Copy for Windows), but xcopy will still work :)
> Luke
hey thank you for the answer that was really very helpfull.
Cool. As you say works like a dream. Just managed to backup my entire xp machine even though copy and paste was broken and I had no internet or network either! Thanks.
if you whant it to be automatic copy,then write this:(from start to end)
if you whant to copy folder from same place to same place:
@Echo Off
Echo Please Press "d"
xcopy "Folder" "Folder2"
if you whant to copy folder from place to other:
@Echo Off
Echo Please Press "d"
xcopy "Folder" "C:/Folder2"
if you whant copy from other place to other place:
@Echo Off
Echo Please Press "d"
xcopy "C:/Folder" "C:/Folder2"
I hope this is what you're looking for...

Just plug this command into your batch file

xcopy "copy from where" "copy to where"

type: xcopy /? to get a list of all the possible switches

example: xcopy /h /e /c /k "\\pcname\share\directory\subdirectory" "C:\documents and settings\jmklss"
Registration date
Wednesday October 8, 2008
Last seen
June 15, 2019
Why not use SyncToy from Microsoft?

check this link
Because not everyone wants to install yet another app when there are perfectly good tools avaliable already.
Thanks, great suggestion!
try xcopy source destination /D parametr
/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
also check link
xcopy source destination /D /I

if you want you can add more switches , check out : xcopy /?
to copy entire directry

xcopy sourcepath destinationpath /e

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!