Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Folder Compare?

Status
Not open for further replies.

demoniac

Programmer
Jun 14, 2001
63
US
Hello. :)

I need to compare two folders, very accurately. I've wrote a program to copy a huge folder from one server to another, and I need a way to confirm that it got there okay. I think if I can find out the number of files in the directory, and their total size, on both the source and destination then that would be a good idea of if it went okay or not. Any help would be greatly appreciated :)

Thanks,
demoniac :eek:)
 
you can compare the folders by using the "dir" statment

example :
dim folder1 as string
dim folder2 as string
dmi f1 as string 'the path of the first directory
dim f2 as string 'the path of the second directory
dim file1 as integer 'number of files in the first one
dim file2 as integer 'number of files in the second one
dim filesize1 as long 'size of files in the first one
dim filesize2 as long 'size of files ni the second one


file1=0
file2=0
filesize1=0
filesize2=0

folder1=dir(f1)
do while folder1<>&quot;&quot;
filesize1=filesize1+filelen(f1 & folder1)
file1=file+1
folder1=dir(f1)
loop

folder2=dir(f2)
do while folder2<>&quot;&quot;
filesize2=filesize2+filelen(f2 & folder2)
file2=file2+1
folder2=dir(f2)
loop
 
If you want to be really certain generate an MD5 hash for each file in the source directory and compare it to an MD5 hash in the destination directory. That should guarantee that the files haven't changed in transit at a bit level.

It will be more time consuming though, but I guess it depends on how much peace of mind you want. If there are lots of files or the files are large (or both) then be prepared for a long wait.

Chaz
 
In reference to 65321's post, I see the method behind it but I can't quite get it to work. I implemented that exact code, the problem is, it never advances to the next file. It finds the first file in the directory and never goes past it. I need a way so that after it has examined the first file (first pass in loop) it will go to the next file. Any ideas?

Thanks,
demoniac :eek:)
 

Dim oFSO As Scripting.FileSystemObject
Dim oFolder As Scripting.Folder

Set oFSO = New Scripting.FileSystemObject
Set oFolder = oFSO.GetFolder(&quot;C:\Temp&quot;)
Set oFSO = Nothing

Debug.Print oFolder.Files.Count
Debug.Print oFolder.Size

Set oFolder = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top