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

Hi Team,

I need to create a program which will compare the two folders and inside that subfolders, if that folder/file is not found then copy that else if it is found on the same folder then need to write log stating that folder/file is already found.

For that purpose do we alreay have any perl inbuilt module to compare the two folders(source and target).

Or we need to write the perl program for that.

Please advise.

Thanks in advance.
Shanmugam A.

  • Comment on compare two folders and copy folder/file if not found on target else log that file or folder

Replies are listed 'Best First'.
Re: compare two folders and copy folder/file if not found on target else log that file or folder
by marto (Cardinal) on Feb 20, 2014 at 15:05 UTC
Re: compare two folders and copy folder/file if not found on target else log that file or folder
by kcott (Archbishop) on Feb 20, 2014 at 15:21 UTC
Re: compare two folders and copy folder/file if not found on target else log that file or folder
by karlgoethebier (Abbot) on Feb 20, 2014 at 15:11 UTC

    Here it is: File::Rsync.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: compare two folders and copy folder/file if not found on target else log that file or folder
by ww (Archbishop) on Feb 20, 2014 at 15:13 UTC
    "...if that folder/file is not found then copy that ..."

    Uh, copying an undef or nul seems fairly pointless. Do you mean 'copy what was found in one into the other?'; 'create a log entry documenting what was NOT found in one that was in the other?' or something else?

    Come, let us reason together: Spirit of the Monastery

      Basically i am comparing two folder (source folder and target folder).

      In the target folder the source folder files/subfolders are not found then copy them. Else if it is found then don't copy that file instead log them stating that respective file already exists.

        OK, that's what I suspected and others discerned to be your meaning. Now let me give you a 'simple english' version that's wordy but utterly unambiguous:
        "I'm comparing two folders. If a file or subfolder is NOT found in the second but is present in the first, copy the missing item from the first to the second; otherwise... simply log that a file or dir was found in BOTH folders."

        Note that this expression does NOT concern itself with items found in the second folder, but not the first. That's a different requirement and requires a different problem statement.

        As with programming, communicating anything even mildly complex depends heavily on clarity and precision.

        Come, let us reason together: Spirit of the Monastery

        Quis custodiet ipsos custodes. Juvenal, Satires

Re: compare two folders and copy folder/file if not found on target else log that file or folder
by wjw (Priest) on Feb 20, 2014 at 19:31 UTC
    ..or just use RSync and be done with it...?

    ...the majority is always wrong, and always the last to know about it...
    Insanity: Doing the same thing over and over again and expecting different results.