Script to Compare File Contents in Two Folders and List Differences?

I've looked through the Forum but can't find anything that seems quite to address my problem--and I'm really new to AppleScript, so please forgive me if this is a dumb question.

I burn a great many files of varying kinds (InDesign, Illustrator, Photoshop, PDF, etc.) to DVD everyday as part of my job. It happens not infrequently, though, that files drop out in the process and don't make it to the disk, with the result that I get calls from Manufacturing saying that I've screwed up and that random files X, Y, and Z are not on the disk that I sent.

I've tried various ways to failproof my burning routine, but utlimately, it seems like something still slips through sometimes--that is, the files are definitely in by Source Folder, but sometimes they don't leap the chasm to the disk. And since there can be several hundred files, it can be difficult to know at a glance if something is wrong.

It would be extremely helpful if there were a script that I could run to compare the contents of the folder source on my desktop (just say its called "Source Folder") with the contents of a disk I have just burned (whose name might vary, but whose folder structure is a duplicate of the subfolders in "Source Folder" that I have burned to disk. All I need the script to tell me is if there are files in my desktop Source Folder than are not on the burned disk).

Is this possible? I'd appreciate any help anyone could offer--right now, I'm printing up the disk directory and a list of the files from my desktop Source Folder and comparing them line for line, and my soul is dying.

Please help!

G5, Mac OS X (10.4.11)

Posted on Jun 30, 2009 11:14 AM

Reply
2 replies

Jun 30, 2009 12:34 PM in response to Wuddus

This can be pretty easily hacked together using a combination of AppleScript and shell scripting.

There's a shell command diff that can tell if two directories are the same or not. You can use AppleScript to put a nice front-end on it, like:

set src to (choose folder with prompt "Select the source directory")
set dst to (choose folder with prompt "Select the destination directory/disk")
try
do shell script "diff -rq " & quoted form of POSIX path of src & space & quoted form of POSIX path of dst
on error theErr
display dialog "The following differences were found:" & return & return & theErr
return
end try
display dialog "Directories match. No differences found"


It's quick and dirty, but should get you started. It runs the diff command which triggers the 'on error' code if there are any differences. The script then reports the differences and exits. If there are no differences the 'on error' code is skipped and you get the all clear message.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Script to Compare File Contents in Two Folders and List Differences?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.