easiest way to compare contents of two folders?

I want to be able to compare two folders and find out which files in folder a are missing from folder b.

I've got a folder with about 8000 files I want to check against another folder which is missing about 300 of the files. I know there is probably a Unix command that will do this quickly but I'm not very proficient in Unix. Could it be done in applescript?

Pedro

G5 Mac OS X (10.4.9)

Posted on May 11, 2007 9:11 AM

Reply
6 replies

May 11, 2007 12:01 PM in response to Peter Robertson

Folder comparisons are harder than you might think.

You first have to decide what constitutes a match and, just as importantly, a miss.

For example, are you basing it purely on file name? What about if files have different sizes? modification dates? etc.

Then there's hierarchies - I'm assuming you want this to delve into subdirectories, so you need it to be recursive. That's not hard, but it's something to consider.

If you're just basing it on name then that's easy enough, but you need to clarify that before delving in.

May 11, 2007 1:41 PM in response to Peter Robertson

This script will ask you to choose two folders to compare, then will output a text file telling you the differences between the two folders:

set folder1 to quoted form of POSIX path of (choose folder with prompt "Select the first folder")
set folder2 to quoted form of POSIX path of (choose folder with prompt "Select the second folder")

try
set shellOutput to (do shell script "diff -r " & folder1 & space & folder2)
on error shellOutput
end try

set nu_file to (choose file name with prompt "Choose a name and location for your report:")
set nu_content to (open for access nu_file with write permission)
try
write shellOutput to nu_content
on error
close access nu_content
end try
close access nu_content

May 11, 2007 4:11 PM in response to Peter Robertson

Hi Pedro,

In AppleScript, something like this:

set f1 to choose folder
set f2 to choose folder -- the folder with missing files
tell application "Finder"
-- get listing of files
set file_list to name of every file of f2
-- move all files that are not in the list
duplicate (every file of f1 whose name is not in file_list) to f2
end tell

As Camelot said, this does not do a recursive check of missing files and does it by name.

gl,

May 14, 2007 1:07 AM in response to Peter Robertson

Hello Peter Robertson,

You may also try 'backup' command in 'Satimage.osax', that is freeware scripting additions made and distributed by Satimage-software, France.

This 'backup' command is actually to synchronize folders, but it has also an option to generate report only, that you may use.

Here's a sample script to compare source and destination folders and generate report on 'missing files' and 'outdated files' in destination folder.

Good luck,
H


-- SCRIPT
(*
* Using Satimage OSAX's
backup

Preparation:
Install Satimage OSAX in:
under OSX (either of the followings)
/Library/ScriptingAdditions/
~/Library/ScriptingAdditions/
under OS9
System Folder:Scripting Additions:

* download sources:
http://www.satimage.fr/software/en/downloads_software.html
http://www.satimage.fr/software/en/soft9.html
*)
set fda1 to choose folder with prompt "Choose master (source) folder."
set fda2 to choose folder with prompt "Choose lesser (destination) folder."
set report to backup fda1 onto fda2 level 0 recursively {true}
return report
-- END OF SCRIPT



Mac OS 9.1.x

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.

easiest way to compare contents of two folders?

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