Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Modified Version 1.1

by sierrathedog04 (Hermit)
on Aug 30, 2001 at 21:08 UTC ( [id://109133]=note: print w/replies, xml ) Need Help??


in reply to Compare Directories and List Changed or Missing Files

This new version takes an optional second parameter which is the path of the target directory. It will thus compare the contents of the directory named in the first parameter with the contents of the directory named in the second parameter.

If there is no second parameter then the program will compare the contents of the directory named in the first parameter with the contents of the current directory.

NOTE: Modified on 9/13/01 to fix bugs and add minor functionality. See comments for additional functionality. Here is the updated code:

# sierrathedog04, jonathansamuel@yahoo.com, August 2001 # First parameter is the target or VOB directory. # Optional second parameter is the source or current directory. # Ver. 1.1, Sept. 13, 2001. Now uses File::Compare instead of diff; # Modified printouts so only files are listed. (Not directories). use strict; require File::Compare; print "\n"; my $targetDir = shift || die "Please pass the name of a target directo +ry enclosed in quotes. \n"; chomp $targetDir; $targetDir =~ s#/$##; # Removes any trailing forward slash from the di +rectory. unless (-d $targetDir) { die "$targetDir is not a valid target directory. Please pass the n +ame of a valid target directory enclosed in quotes. \n"; } my $sourceDir = shift || "."; opendir THISDIR, $sourceDir; my @allFiles = grep { $_ ne '.' and $_ ne '..' && -f $_} readdir THIS +DIR; closedir THISDIR; foreach (@allFiles) { print "$_ in source directory $sourceDir differs from that in + target directory $targetDir\n\n" if File::Compare::compare("$sourceD +ir/$_", "$targetDir/$_") == 1; print "$_ found in source directory $sourceDir but not in targ +et directory $targetDir\n\n" if File::Compare::compare("$sourceDir/$_ +", "$targetDir/$_") < 0; } print "\n...Finished checking source.\n\n\n"; opendir targetDIR, $targetDir; my @alltargetFiles = grep { $_ ne '.' and $_ ne '..' && -f $_} readd +ir targetDIR; foreach (@alltargetFiles) { print "$_ found in target directory $targetDir but not in sour +ce directory $sourceDir\n\n" if File::Compare::compare("$sourceDir/$_ +", "$targetDir/$_") < 0; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-28 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found