Mac [Applescript] Comaparing two folders' contents

BobRon

macrumors member
Original poster
Oct 13, 2012
34
7
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
 

chown33

Moderator
Staff member
Aug 9, 2009
8,445
4,448
Pale blue comma
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.
 

BobRon

macrumors member
Original poster
Oct 13, 2012
34
7
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
 

chown33

Moderator
Staff member
Aug 9, 2009
8,445
4,448
Pale blue comma
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.
 
Last edited:

BobRon

macrumors member
Original poster
Oct 13, 2012
34
7
Yeah, basically. No updating files, just copying inexistent ones. And I am running 10.6.8
 

ghellquist

macrumors regular
Aug 21, 2011
146
1
Stockholm Sweden
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,445
4,448
Pale blue comma
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.
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.