PDA

View Full Version : compare files in folders while ignoring specific subpaths?


Tremeoc
08-25-2008, 09:16 AM
Hi all,

I would like to recursively compare the file contents of two folders while ignoring specific filepaths. In other words, I have a bunch of files in folder A arranged in various different subfolders. In folder B I have (hopefully - well, this is what I want to check), exactly the same files, but arranged in different subfolder structures.

So what I want to see is whether file1,file2,...filen in Folder A also exists somewhere in Folder B, regardless of exactly where it is in the subfolder structure.

Does that make sense? I can't find an option in diff to do this. Are there any other ways?

TIA for any help,
T

robinwmills
08-25-2008, 03:21 PM
You could use find to create your list in each folder - then do a diff. Find's a 'swiss army knife' - loads of options - enough to cut off your fingers! In it's simplest form you can:

cd folderA
find . > /tmp/folder!
cd folderB
find . > /tmp/folderb
diff /tmp/foldera /tmp/folderb


You could filter the output from each directory to remove stuff (or just edit it with TextWrangler). If you're only doing this once - editing is probably quick and simple. If want a script to run every day from the rest of your life, well you'll probably find studying find and egrep to be worth the effort.

Tremeoc
08-25-2008, 06:14 PM
Thank you so much!

That worked great once I'd regex'd out the paths in the lists just to leave the filenames. Amazing how things can go missing when you are copying large folders. ;)