Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: compare files and folders

810 views
Skip to first unread message

Pegasus (MVP)

unread,
Feb 7, 2008, 4:25:32 AM2/7/08
to

"Jeroen" <Jer...@discussions.microsoft.com> wrote in message
news:70515C69-2609-4E60...@microsoft.com...
> Hi,
>
> We use a couple of scripts that install several applications, copy's
> files,
> set registry settings, and so on... Now I'm working on a script that
> checks
> to see if the server installed ok. One of the parts that I would like to
> check is a comparison of a local directory and a network folder (that
> should
> have copied locally). I've been breaking my brain on several methods on
> doing
> this, but nothing good so far and was hoping to find some help here.
>
> What I've come up with, so far is scanning the two folders (recursively),
> putting this information in two arrays and compare one with the other.
> This
> is just theoretical though, because uptil now I've only succeeded in
> recursively scanning the folder.
>
> regards,
>
> jeroen

Are you trying to compare the contents of the folders by file name,
size and date or by performing a binary comparison of the contents
of the files?


Jeroen

unread,
Feb 7, 2008, 4:37:01 AM2/7/08
to
Hi,

I'm currently checking on size and created (by a lot of copy pasting) the
following:

Function CompareFolders (folder1, folder2, Lvl1, Lvl2, Lvl3) 'source folder,
destination folder

Dim fso, fo1, fo2, fi1, fi2, f

Set fso = CreateObject("scripting.filesystemobject")
Set fo1 = fso.getfolder(folder1)
If fso.FolderExists(folder2) Then
Set fo2 = fso.getfolder(folder2)
Set fi1 = fo1.Files
For Each f In fi1
If fso.fileexists(fo2.Path & "\" & f.Name) Then
Set fi2 = fso.getfile(fo2.Path & "\" & f.Name)
If fi2.Size <> f.Size Then
logtxt = f.path & " not copied correctly"
Loglvl Lvl1, logtxt
wscript.echo f.path & " not copied correctly"
End If
Else
logtxt = "Missing file: " & f.path
Loglvl Lvl2, logtxt
Wscript.echo "Missing file: " & f.path
End If
Next

dim s
for each s in fo1.subfolders

Aspad = split(s.path, folder1, -1, 1)
Sspad = Aspad(1)

sfolder2 = folder2 & Sspad
If fso.FolderExists(sfolder2) Then
CompareFolders s.path, sfolder2, Lvl1, Lvl2, Lvl3
Else
logtxt = sfolder2 & " doesn't exist"
Loglvl Lvl3, logtxt
wscript.echo sfolder2 & " doesn't exist"
End If
next
Else
logtxt = folder2 & " doesn't exist"
Loglvl Lvl3, logtxt
wscript.echo folder2 & " doesn't exist"
End If

End Function


The Loglvl part is used to write to a html log.

any tips or tricks?

regards,

jeroen

Pegasus (MVP)

unread,
Feb 7, 2008, 8:03:09 AM2/7/08
to
While a purist would use a recursive process to access a whole
folder tree, I tend to be lazy and apply the KISS principle: Why
re-invent the wheel if other people have already created the
perfect wheel for me? The command

dir d:\temp\*.txt /s /b

will generate an output of the form

D:\temp\Temp\xxcopy.txt
D:\temp\Netgear\NetGear\HELP\DIAG.TXT
D:\temp\Netgear\NetGear\HELP\INST_DOS.TXT
D:\temp\Netgear\NetGear\HELP\README.TXT

which seems perfectly suited for my purposes. All I need to
do is this:
1. Pick up one line at the time.
2. Replace D:\Temp with \\server\share\folder (for example).
3. See if the target file exists.
4. See if the file sizes are the same.

This is exactly what the following function does. As I said,
it's an application of the KISS principle.

F1 = UCase("d:\Temp")
F2 = UCase("d:\Thu")
Compare F1, F2

Sub Compare (Folder1, Folder2)
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjWshShell = WScript.CreateObject("WScript.Shell")
Set StdOut = WScript.StdOut
Set ObjExec = ObjWshShell.Exec("%ComSpec% /c dir /s /b " _
& """" & Folder1 & "*.txt""")

Do While Not ObjExec.StdOut.AtEndOfStream
File1 = UCase(ObjExec.StdOut.ReadLine)
File2 = Replace(File1, F1, F2, 1, 1)
If ObjFSO.FileExists(File2) Then
Set F1 = ObjFSO.GetFile(File1)
Set F2 = ObjFSO.GetFile(File2)
If Not F1.Size = F2.Size Then
'Sizes are different - put your own code here
End If
Else
'File does not exist - put your own code here
End If
Loop
End Sub

"Jeroen" <Jer...@discussions.microsoft.com> wrote in message

news:0CA02B52-0B5C-4A6C...@microsoft.com...

Chaitanya

unread,
Feb 8, 2008, 9:25:03 AM2/8/08
to
Hi,

To do this there is one Utility available from Microsoft,

search for windiff

i think its available in XP SP2 Supprt tools
--
Regards,
Chaitanya Shah

0 new messages