| 1. |
Solve : batch file to compare folders and subfolders? |
|
Answer» I am trying to write a batch file to compare the contents of a folder and its subfolders and return true or false based on whether the files they contain are the same. (It will be part of an if statement that deletes one of the folders if they are equal). i was just experimenting with the command with a couple of text files, Code: [Select]S:\>echo hello>file1.txt S:\>copy file1.txt file2.txt 1 file(s) copied. S:\>echo goodbye>file3.txt S:\>set result=false & fc file1.txt file2.txt>nul && set result=true S:\>echo %result% true S:\>set result=false & fc file1.txt file3.txt>nul && set result=true S:\>echo %result% false Thanks guys. Trout, that looks like what I want, but I'm rather new to dos commands so could you explain the syntax of this line?: S:\>set result=false & fc file1.txt file2.txt>nul && set result=true Also, would this work with folders instead of files? and would it include subfolders? Thanks!Quote from: your.name812 on July 24, 2009, 01:05:02 PM
(1)Create a VARIABLE called 'result' and set its value to the string 'false' (2) compare 2 files and send the output to the nul device so it doesn't SHOW on screen (3) use the && operator to test the errorlevel (the command after the && is only executed if there was no error, i.e. no differences were found) and if no differences were found set the value of the variable 'result' to 'true' Quote Also, would this work with folders instead of files? and would it include subfolders? Folders yes Code: [Select]fc dir1\*.* dir2\*.* Subfolders no Excellent. Thanks very much |
|