|
Answer» Is there any way with BATCH or VBS Ect.. to compare 2 diff files in 2 diff DIRECTORIES that have the same name but diff file sizes or md5 Ect.. So if the the source file (File that will be copied to dest) is diff from the dest file, then append (1) to the dest file name, then copy the source file over to the dest directory
Ex: I want xcopy to copy F:\files\data.txt over to C:\files\F\data.txt but if C:\files\F\data.txt already exists and is a TOTALLY diff file than F:\files\data.txt then I want a way to compare F:\files\data.txt against C:\files\F\data.txt and if F:\files\data.txt is diff from C:\files\F\data.txt than I want C:\files\F\data.txt to be renamed to C:\files\F\data(1).txt then have xcopy copy F:\files\data.txt over to C:\files\F\data.txt
Is there anyway to do this at all..??
Code: [Select]for /f "tokens=* delims=" %%A in ('dir /b /a:-d') do ( comp F:\files\%%A C:\files\F\%%A if errorlevel==1( set add=%%A set add=%add:~0,-4% ren c:\files\F\%%A c:\files\F\%add%(1).txt ) xcopy F:\files\%%A C:\files\F\%%A )
appologies if there are any errors in that, i wrote it quickly...
FBthanx, is there anyway to make it so its not file specific though. so if i wanted to Mirror Xcopy the entire folder F:\Files to C:\files\F it would copy all the Sub-Dirs + Sub-Files from F:\Files over to C:\files\F\Files and if it ran into any duplicate same named files already existing in C:\files\F\Files than it would append (1) to any of those specified duplicate named files.. then copy over the new files..the only difference i can see in your second post is that you want to copy sub-directories and sub-files to do this use the /E argument on xcopy; substitue this line in for the one above:
Code: [Select]... xcopy F:\files\%%A C:\files\F\%%A /E ... FBIs there anyway to do the Xcopy /e /i first and then when it runs into existing destination file and asks you to overwrite, do the comparing then and if they are diff files append (1) to the existing dest file name, then xcopy over the new source file to the dest dir... why don't you use the "/y" switch, when there is a file that already exist in the dstination folder,the command line will stop there and then prompt you a message! but i'm trying to make an automated script to do it all without any prompting..Have you ever tried fireballs' CODE?Start again !!!
I suggest you DOWNLOAD WinMerge from SourceForge.
You aim at two targets - the two points on each drive to be compared.
It compares every file in each designated directory, and all their sub-directories.
Comparison is quick - e.g. 1 minute for 40,000 files on my Drive C:\ w.r.t. Drive L:\ USING File size comparison - similar time using file date option, or a coffee break using a detailed examination of every byte in every file (that gives it 7 GByte to read !!!).
The results appear with one file name per row and :- If it matches between both targets, If it is different between both targets, or Which target it is unique to.
Normal use is to click on any row, and a file comparison shows you all the differences between them.
You do not have to use the built in file comparator.
You can simply copy what it has found different to any other location for any sort of independent processing by your preferred tools.
e.g. you can rapidly select all desired files/subdirectories of one target, and either copy them or move them to the other target, or even to a totally different choice on another drive, where what you desire can be unique, different, or identical - you can even mix and match.
Regards Alan
Quote from: qinghao on August 30, 2008, 11:02:41 AM Have you ever tried fireballs' CODE?
yes, but its only comparing files in the F:\files\ Dir only, but not in any of F:\files\ sub Dir's or Files.. then it copies them one by one all into the same DIR C:\files\F\ without mirroring the Complete Folder-File Structure of F:\
What I want to do is something like this
for /f "delims==" %%S in ('DIR F:\ /A /B /S') do ..... for /f "delims==" %%D in ('DIR C:\Files\F /A /B /S') do .....
%%S = Source Files %%D = Dest Files
Xcopy F:\ C:\Files\F /E /I If Ask for overwrite comp %%S to %%D If if errorlevel==1 ren %%D %%D(1) then copy over the new source filesthe fc command (if you have it) does what you want.OK THNX, but how to INCORPORATE it with either: Xcopy F:\ C:\Files\F /E /I or robocopy F:\ C:\Files\F /MIR
|