Hello, I am new to programming and thus also new to Perl. I've been googling, using "Perl for System Administration", looking in various Perl CD Bookshelf volumes, but am not really clearly seeing the answers that are probably there looking me in the face. In English what I am researching how to do (in Win2k) is:
1) Recursively compare folderA (mapped) and folderB (local) and their subdirs.
2) Determine which files are out of sync (in this case meaning: different --newer-- versions exist, or one folder doesn't have the same files as the other.)
3) In the files where differences exist (in time stamps) copy the file(s) with the newer time stamp over to the second folder (the one with the older ---or missing --files, overwriting if necessary).
4) Copy the files that don't exist over, so that both directories have the same files
I've found something along the lines of:
my $file_date=localtime((stat("$file"))[9]);
for the time stamp info. I've found snippets of code here and there to come up with this:
#!/usr/bin/perl -w #!C:\Perl\bin\perl -w my $directory='/devl/bin'; my $size=0; my $file; my $file_date=localtime((stat("$file"))[9]); opendir(DIRHANDLE, $directory) or die "couldn't open $directory : $!\n +"; my@files = grep(!/^\.\.?$/,readdir(DIRHANDLE)); foreach $file (@files) { $size=(-s "$directory/$file"); print "$directory,$file,$size,$file_date"; print "\n"; } closedir(DIRHANDLE);
but that's about as far as I've gotten, which feels like a long way from the desired result.

What I'm still lost on finding out is how to recursively compare two separate directories, and also how the if different files, compare their dates, when date is newer (of if file doesn't exist in one directory), copy to directory missing file(s) and/or older versions.
Thanks for any clues.

In reply to recursively compare folders in windows, synchronize the two folders with the newest files by dkaplowitz

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.