# 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). + # Ver. 1.2 Sept. 19, 2001. Accepts optional parameters 'modified' and +'created' followed by directory names. If these parameters are used then the program wil +l copy all modified files to the modified directory and all changed files to the changed +directory. + use strict; + require File::Compare; + + use Getopt::Long; + my $modifiedDir; + my $createdDir; + GetOptions("modified:s" => \$modifiedDir, "created:s", => \$createdDir +); $| = 1; + + 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.\nPlease pass the +name of a valid target directory enclosed in quotes. \n"; } my $sourceDir = shift || "."; unless (-d $sourceDir) { die "$sourceDir is not a valid source directory.\nPlease pass the +name of a valid source directory enclosed in quotes. \n"; } if (defined $modifiedDir){ unless (-d $modifiedDir) { die "$modifiedDir is not a valid modified directory. \ +nPlease use the --modified option to pass the name of a valid directo +ry \nto which you wish to copy all modified files."; } } if (defined $createdDir){ unless (-d $createdDir) { die "$createdDir is not a valid created directory. \nP +lease use the --created option to pass the name of a valid directory +\nto which you wish to copy all created files."; } } opendir THISDIR, $sourceDir; my @allFiles = grep { $_ ne '.' and $_ ne '..' && -f "$sourceDir/$_"} + readdir THISDIR; closedir THISDIR; foreach (@allFiles) { if (File::Compare::compare("$sourceDir/$_", "$targetDir/$_") = += 1) { print "$_ in source directory $sourceDir differs from + that in target directory $targetDir\n\n"; print `cp $sourceDir/$_ $modifiedDir/$_` if defined $ +modifiedDir; } elsif (File::Compare::compare("$sourceDir/$_", "$targetDir/$ +_") < 0) { print "$_ found in source directory $sourceDir but not + in target directory $targetDir\n\n"; print `cp $sourceDir/$_ $createdDir/$_` if defined $m +odifiedDir; } } 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; }

In reply to Ver. 1.2: Compare Directories and List Changed or Missing Files by sierrathedog04
in thread Compare Directories and List Changed or Missing Files by sierrathedog04

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.