|
Answer» Im trying to figure how I can scipt using a batch file the differences between two directories and only copying only the difference of the two to a new folder, such as lets say fold1 has files 1,2,3 and fold2 has 1,2,3,4,5,6. I want only 4,5,6 copied. thanksThere are too many variables to GIVE a definitive answer. Are you only basing this on file names or do date and times enter into this picture? What OS are you using?
If you have XP, there is a nifty little free utility that will do this: SyncToy
Let us know. 8-)Thanks, for the quick response! a utility would be great to use except for, this is going to be part of an automated script. I need to be able to do this from the command prompt..I need to be able to compare on a file to file bases not based on Date.If you have two directories, for example, d1 and d2, you may try something like:
for %%v in (dir d1) do ( if not exist d2/%%v copy %%v dest. )
Repeat this for d2
This is not the exact batch. Just some thoughts. Good luck!
Code: [Select]@echo off set d1=c:\dir1 set d2=c:\dir2
for /f %%a in ('dir /B %d1%\*.*') do ( if not exist %d2%\%%a copy %d1%\%%a %d2% ) for /f %%a in ('dir /b %d2%\*.*') do ( if not exist %d1%\%%a copy %d2%\%%a %d1% )
Change dir1 and dir2 to your local settings.
Hope this helps. 8-)The Example sidewinder posted was perfect, if you have files that are named with spaces you will want to add "TOKENS=1* DELIMS=" to your FOR and PUT quotes around "%d2%\%%a"
(Example)
for /f "TOKENS=1* DELIMS=" %%a in ('dir /b %d1%\*.*') do ( if not exist "%d2%\%%a" copy "%d1%\%%a" %d2%Thanks! for everyones help! I will try these out and let you knowJust incase.
If there are sub directories under the souce fulder it is going to copy all the files from those FOLDERS into the ROOT of your destination folder. To prevent that from happening add /a:-d
'dir /b /a:-d %d1%\*.*'
|