[Applescript] Comaparing two folders' contents

Discussion in 'Mac Programming' started by BobRon, Apr 12, 2014.

  1. BobRon macrumors member

    Joined:
    Oct 13, 2012
    #1
    Hi,
    In Applescipt, I was recently trying to compare the contents of two folders and identifying missing files. For instance, I have Folder A and Folder B. I want to compare Folder B's contents with Folder A's, and identify which files Folder B does not have that Folder A does. This should be within the subfolders also.
    Make sense?
    Thanks,
    BobRon
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Are you doing this to learn AppleScript, or are you doing this to solve a problem?

    AppleScript may not be the best or simplest choice to do this.
     
  3. BobRon thread starter macrumors member

    Joined:
    Oct 13, 2012
    #3
    Chown33,
    Thank you for replying. I do, in fact, need to solve a problem. I was wondering if you could suggest an alternative way to go about this. I should probably mention I am trying to copy the missing files into Folder B, if that can help.
    Thanks,
    BobRon
     
  4. chown33, Apr 12, 2014
    Last edited: Apr 12, 2014

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Just to clarify, you only want to copy missing files into B. You don't want to compare two files that both exist, and copy the later one into B, or do anything at all if two files exist in both A and B. Because only copying missing files is a simpler problem to solve.


    Also, please identify your exact OS version.
     
  5. BobRon thread starter macrumors member

    Joined:
    Oct 13, 2012
    #5
    Yeah, basically. No updating files, just copying inexistent ones. And I am running 10.6.8
     
  6. ghellquist macrumors regular

    Joined:
    Aug 21, 2011
    Location:
    Stockholm Sweden
    #6
    To me (and we all differ) creating this kind of utilities is all about being lazy. Simply getting things done.

    One of my favourite ways of being lazy is to follow the Unix way of combining existing utilities in chains. And one of the really good utilities to know is the rsync command.

    In order to get a list of what files to "update" or "sync" between two libraries, the command is.

    rsync --dry-run --verbose --update /source /destination

    You can get the rsync command to do a lot of things for you. It is among other things a very capable backup solution.
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    I think you'll need -r (--recursive) on that. Also, he said he didn't want to update existing files, so --ignore-existing would also be needed.

    I recommend testing the command using two test directories. One could put them in ~/Documents, naming them A and B. Then copy various sets of files in, run the command, and make sure that the output is as expected.
     

Share This Page