Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Delete matching files in two Finder folders Desktop
If you have two folders that have certain files in common, and you want to delete all the items in the second folder that have the same name as an item in the first folder, here's how to do it:
  1. Select All in the first folder.
  2. Drag the selection onto the second folder.
  3. Select 'Replace' and check 'Apply to All' in the resulting dialog.
  4. Choose Edit: Undo Copy of nn Items from the Finder's menu.
This will undo the move of files from folder #1 to folder #2, but it will not undelete the matching items in folder #2 which were replaced by the copy. This is not unlike the "Difference" operation in set theory.

[robg adds: I'm not sure whether this is a bug or a feature, but it does work as described. I tested it in both 10.3 and 10.4.]
    •    
  • Currently 2.25 / 5
  You rated: 2 / 5 (4 votes cast)
 
[9,129 views]  

Delete matching files in two Finder folders | 9 comments | Create New Account
Click here to return to the 'Delete matching files in two Finder folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Delete matching files in two Finder folders
Authored by: lagroue on Sep 13, '05 01:08:15PM

Yet another report-a-bug friday, except we're only tuesday !



[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: jacobolus on Sep 13, '05 04:33:34PM

Another good reason why, as John Gruber suggests, replaced files should be moved to the trash, not deleted outright! Definitely a bug if it results in unintentional data loss.



[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: SeanAhern on Sep 13, '05 07:44:04PM

That might be difficult to implement system-wide. If a (non-Finder) app were operating with a C API, for instance, doing an open(filename, "w") on an existing filename, you would have to capture this at the filesystem level and "Do The Right Thing" (TM), that is, move the file to the appropriate .Trash location. That doesn't exist in any existing filesystem, and you would be hard pressed to do it for legacy filesystems.

Maybe you could write a shim to the "open" system call, but that could cause performance problems and might violate POSIX compliance.



[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: jacobolus on Sep 14, '05 11:19:32AM

Except that we're talking here about the Finder, not third party apps that are opening files for writing. I'm not suggesting that a unix mv, or a call to write to a file move a file it's replacing to the trash, merely that the Finder do so. Then we could avoid problems such as this one of having the Undo command not actually undo all changes, in the process possibly losing important data.



[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: sjk on Oct 09, '05 04:43:14PM

I agree with your simple analysis and explanation. Here's looking at the two main perspectives in more detail:

From Finder, crippling Undo context by not restoring files that were replaced by the copy or move is quite arguably a bug because it redefines Undo's anticipated (and intuitively intended, especially for novices) meaning and behavior. However, that does have issues like mmacho mentioned. Anyway, at least for me, Undo usually means "restore everything affected by an action to the state it was in before that action".

From a shell, traditional versions of commands like cp and mv are defined and designed to be irreversibly destructive. There are non-destructive replacements available but unless underlying syscalls are modified (e.g. like SeanAhern's shim) there are too many ways to circumvent non-destructive behavior.

And that leaves us with a mix of what's expected, what's possible, and what actually happens. :-)



[ Reply to This | # ]
"Matching" is by name only...
Authored by: gabester on Sep 14, '05 01:14:53PM

WARNING:
(This should be self evident to any long-time user of the Finder.)

I'd hoped that this would somehow magically work to delete files with identical data... i.e. if I have "Image_001.jpg" in folder A and move it to folder B where "My vacation.jpg" - a renamed but otherwise identical version of the file existed.

So be forwarned, if you have 2 files with the same name but different data, say "Notes.txt" in your "Home Ec Class" and "Molecular Biology" folders, and you move the "Notes.txt" file to Molecular Biology, then there go your notes about mitochondria, replaced by how long to boil an egg...

g=



[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: juanfal on Sep 15, '05 05:13:20AM

Finder can't undo everything it does! The "Undo" name of the Finder under Edit menu is a joke of Apple Engineers.

Imagine yourself translating a File over a mounted volume via a network connection and with only dropping permission (you can write once, never delete). How in the hell Finder could "undo" such action?

Many of the Finder actions are conditioned by the file permissions structure and the disk space available. If you could want to undo a file overwriting, Finder previously ought to hold a copy of the original file (megabytes of gigabytes) to allow such posibility. It did so with the scrapbook mechanism when you copy a huge amount of bytes. Some applications, like Micro$oft's, ask you about keep it before quiting. A reasonable question but also an indication of limits, natural limits in the hardware. Files are going to be bigger and bigger and this problems should arise with the time more frequently.



[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: Zo-1 on Sep 20, '05 08:17:26PM

I didn't know this was either hint or bug. Has always seemed like common sense to me:

The items that remain go to the trash. Or vice versa. According to your critera, creation date, version, whatever.

.

[ Reply to This | # ]
Delete matching files in two Finder folders
Authored by: pcunix on Oct 09, '05 04:12:07AM

One small thing:

A "." file in the set will stop the entire process.

This is something easy to do in Terminal; see http://aplawrence.com/Basics/undo-bad-archive.html for details but basically just

cd dir2
for i in *
do rm -rf "/dir1/$i"
done

That doesn't complain about "." files, but it won't remove them either.


---
--
Tony Lawrence
Free SCO, Mac OS X and Linux Skills Tests: http://aplawrence.com/skillstest.html



[ Reply to This | # ]