Creating a Batch File to copy a directory [Solved/Closed]

Waqas - Oct 15, 2008 at 11:37 AM - Latest reply:  BB
- Apr 28, 2011 at 03:44 PM
Hello,

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....
See more 

14 replies

Best answer
55
Thank you
try XCOPY with parameter /S or /E

example:

XCOPY C:\Temp C:\Temp2 /S

Thank you, Igo309 55

Something to say? Add comment

CCM has helped 1704 users this month

40
Thank you
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
the batcher(learner) - Sep 26, 2009 at 03:15 PM
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
Luke > the batcher(learner) - Oct 25, 2009 at 03:23 PM
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 :)
thebatcher(learner) > Luke - Nov 3, 2009 at 08:24 AM
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.
18
Thank you
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"
exit
------
if you whant to copy folder from place to other:
@Echo Off
Echo Please Press "d"
xcopy "Folder" "C:/Folder2"
exit
------
if you whant copy from other place to other place:
@Echo Off
Echo Please Press "d"
xcopy "C:/Folder" "C:/Folder2"
exit
15
Thank you
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"
xpcman 19100 Posts Wednesday October 8, 2008Registration dateContributorStatus July 16, 2018 Last seen - Oct 15, 2008 at 04:59 PM
11
Thank you
Why not use SyncToy from Microsoft?

check this link

http://blogs.msdn.com/...
Because not everyone wants to install yet another app when there are perfectly good tools avaliable already.
Thanks, great suggestion!
9
Thank you
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
http://www.computerhope.com/xcopyhlp.htm
fuckingmoron - Nov 2, 2008 at 06:26 AM
7
Thank you
xcopy source destination /D /I

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


xcopy sourcepath destinationpath /e