Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: file comparison

by ramlight (Friar)
on Jun 26, 2009 at 19:42 UTC ( #775153=note: print w/replies, xml ) Need Help??


in reply to file comparison

If you are doing this a lot with large files, computing a cryptographic hash is the way to go. If, on the other hand you are:

1) Working on Windows
2) Working over network shares
3) Not doing too much

This little snippet I threw together the other day to compare the contents of two shares might help:

my $share = '\\\\someserver\\someshare\\"' foreach my $file (@file_list) { my $file2 = $share . $file; if (-e $file2) { my @cmp = `fc $file $file2 | findstr /c:"FC:"`; if ($cmp[0]) { unless ($cmp[0] =~ /no differences/) { print "$file: $cmp[0]"; } } else { print "$file:\n" } } else { print "$file is missing from $share\n"; } }

Replies are listed 'Best First'.
Re^2: file comparison
by Karger78 (Beadle) on Jun 26, 2009 at 19:58 UTC
    Thanks for your method. i am doing a file compare on windows. will your snip work even if the file names are different but the size is the same?
      Yes. You just have to feed the appropriate file names to the fc command and look at what it gives you back. It so happened that I was comparing two shares to see where they differed, not quite the same as your problem ... but close enough.
        I decided to do it the md5 way. So how would i accomplish this. I have it reading the directorys assign it to an array. Right now I am just printing the md5 hash from each element in the array. How would I assign each item to the array, and then loop though each array and compare each field?
        opendir(DIR, $RemoteSubDirectory); my @rFileCheck = readdir(DIR); closedir(DIR); opendir(DIR, $localCpPath); my @lFileCheck = readdir(DIR); closedir(DIR); my $c1; foreach (@lFileCheck) { print md5_base64($lFileCheck[$c1]); print "\n"; $c1++; } my $c2; foreach (@rFileCheck) { print md5_base64($rFileCheck[$c1]); print "\n"; $c2++; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://775153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-10-02 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (11 votes). Check out past polls.

    Notices?