Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a script that can run under NT or 98 that would keep files synchronized between two directory trees across a network. I found one perl script that seemed to do what I want, but appeared to require features only found on Linux. I have a laptop and a desktop and want to be able to schedule automatic synching of certain directory trees. Does such a script or program already exist? How difficult would something like this be to write in Perl? I am an intermediate newbie and so was looking for something already done, but am always willing to learn more about Perl! Thanks in advance!

Replies are listed 'Best First'.
Re: Perl script for syncing files
by buzzcutbuddha (Chaplain) on May 17, 2000 at 18:22 UTC
    The method you would follow would depend on the nature of files that you are attempting to sync.
    Are they flat text or are they Office documents, etc?

    Some more information about the files will help us all help you.

    UPDATE

    At the very least, you could modify this:
    $file1 = 'C:\baz1.txt'; $file2 = 'C:\bar1.txt'; if (-M $file1 < -M $file2) { print "baz is newer than bar"; } elsif (-M $file1 > -M $file2) { print "bar is newer than baz"; } elsif (-M $file1 == -M $file2) { print "bar and baz are equal"; } else { print "foo, that didn't go well!"; }

    That is very rudimentary. You would want to test for the file existence, etc. But that should give you the idea. hth.
Re: Perl script for syncing files
by turnstep (Parson) on May 17, 2000 at 20:01 UTC
    It all depends on what exactly you mean by "synchronized." Are you content to check the last modificatin time, or do you want to check the files themselves. Either way, perl can handle it. :) The above code is a good start (although I would store the values of -M $file1 so that it is not called more than once) and you can throw in some read commands to actually compare the contents. Sounds like a great project for you to try - be sure to ask perlmonks if you get stuck! (and post it to Craft when you are done)

      You're right, I should have stored the -M $file1; in a var. I was just
      trying to bang that out fast as an example...should have thought of that
      though. ooops!