File comaprision using batch file

Closed
WENzER - Mar 9, 2010 at 11:32 PM
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 - Mar 21, 2010 at 11:51 AM
Hello,
I have two folders. I want to compare the files inside the folders.There are some subfolders in root folders. These sub folders are also containing some files. I want to comapre these files in subfolder also. For that I am trying to write a batch file. Any kind of solution will be appreciated

3 replies

Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 14
Mar 17, 2010 at 10:05 AM
No, the scripts I posted are windows scripts. Install biterscripting, and run the scripts on two test root folders.
1
I dont know anything about biter scripting. Will your script comapre files also
0
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 14
Mar 21, 2010 at 11:51 AM
Compare the contents of two files ?

Use something like this

var str file1, file2, content1, content2
cat $file1 > $content1
cat $file2 > $content2
if ( $content1 <> $content2)
echo "Files " $file1 " and " $file2 " have different content."
endif

If the files are binary, use the -h flag in the cat command.
0
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 14
Mar 15, 2010 at 10:18 AM
Let's first write a script that will compare files (existance) in two folders ( not subfolders )

# Script CompareFolders.txt
var str folder1, folder2, list1, list2
lf -n "*" $folder1 ($ftype=="f") > $list1
lf -n "*" $folder2 ($ftype=="f") > $list2
if ($list1 <> $list2)
    echo "Folders " $folder1 " and " $folder2 " are different."
endif


Copy and paste this script into file C:/Scripts/CompareFolders.txt.

Let's now write another script that will compare two root folders, using the above CompareFolders.txt script.

# Script CompareRoots.txt
var str roo1, root2, list1, list2, folder1, folder2
lf -r -n "*" $root1 ($ftype=="d") > $list1
lf -r -n "*" $root2 ($ftype=="d") > $list2
while ($list1 <> "")
do
    lex "1" $list1 > $folder1
    lex "1" $list2 > $folder2
    script "C:/Scripts/CompareFolders.txt" folder1($folder1) folder2($folder2)
done



Copy and paste this script into file C:/Scripts/CompareRoots.txt.

These scripts are in biterscripting. Start biterscripting and enter this command.

script "C:/Scripts/CompareRoots.txt" root1("C:/testfolder1") root2("C:/testfolder2")


It will compare all folders and subfolders, at all levels, within C:/testfolder1 and C:/testfolder2. It will show you a list of folders and subfolders that don't match.

I have seen such scripts used for comparing two computeres. If you are trying to do that, when comparing the entire hard drives on two computers, the script will take some time to complete, before you see any output.
0
But its a unix script, for dat one must have Unix box. What if I want to use only Dos command.
And My actual problem is:
I have two folders with sub folders. One folder is base folder other one is local folder.These folders & subfolders consist of identical as well as non identical files. I want to compare these folders and report the result in some other file. This report must consist of
1. List of All identical files
2. List of All modified files
3. List of Any missing file or folder
4. List of All non identical file

I have tried following script. But it has given only the file difference and missing file.

for /f "delims=" %%a in ('dir/b/a-d c:\test\1') do (
if exist "C:\test\2\%%a" (
fc "c:\test\%%a" "C:\test1\%%a" >> compare.log
) else (
echo %%a is missing >> missing.log
)
)
-1