Creating a Batch File to copy a directory

Solved/Closed
Waqas - Oct 15, 2008 at 11:37 AM
 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....
Related:

8 responses

try XCOPY with parameter /S or /E

example:

XCOPY C:\Temp C:\Temp2 /S
57
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
40
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
0
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 :)
0
thebatcher(learner) > Luke
Nov 3, 2009 at 08:24 AM
hey thank you for the answer that was really very helpfull.
0
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.
0
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
18
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"
15

Didn't find the answer you are looking for?

Ask a question
xpcman Posts 19530 Registration date Wednesday October 8, 2008 Status Contributor Last seen June 15, 2019 1,825
Oct 15, 2008 at 04:59 PM
Why not use SyncToy from Microsoft?

check this link

https://docs.microsoft.com/en-us/archive/blogs/
11
Because not everyone wants to install yet another app when there are perfectly good tools avaliable already.
0
Thanks, great suggestion!
0
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
https://www.computerhope.com/xcopyhlp.htm
9
to copy entire directry


xcopy sourcepath destinationpath /e
6
xcopy source destination /D /I

if you want you can add more switches , check out : xcopy /?
0