Negative Search (does NOT contain)

Does anyone know how to search for files in a particular directory that do NOT contain a particular word, either capitalized or lower case?


I have a pile of several thousand files that I want to purge of files that do NOT contain a particular word, so I can delete them. Just about any software program would work for me, though I'm not up to speed on Spotlight; I don't know how to limit the search to a specific folder.


Thanks.

MacBook Pro

Posted on Dec 2, 2012 1:04 PM

Reply
12 replies

Dec 2, 2012 1:45 PM in response to David Blomstrom

OK, I think I get it...


I found AppleScript in Utilities. I want to test this before I delete anything, so I changed your code to this:


tell application "Finder"

find (every file of folder Trash_Recovery that does not contain "physiology")

end tell



I want to find files in a folder on my external hard drive named Trash_Recovery (external hard drive/Storage/Trash_Recovery) that does not contain the word "physiology." So I opened a Finder window and navigated to Trash Recovery. When I ran AppleScript, I got the following message:


Expected expression but found "does not"


I assume that means I haven't written the script correctly.

Dec 2, 2012 2:12 PM in response to Niel

I must be confused; I'm not trying to find or delete files that are NAMED Physiology.php; I want to find files that do not contain the word "physiology." The code you gave me looks right (or what I'd expect)...


tell application "Finder"

select (every file of folder Trash_Recovery that does not contain "physiology")

end tell


I don't see how or where I would insert "whose name" in that code. However, I tried the following:


tell application "Finder"

select (every file of folder Trash_Recovery whose name does not contain "physiology")

end tell


I got the error message "The variable Trash_Recovery is not defined."


This AppleScript thing is exciting, though; I didn't even know it existed!

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.

Negative Search (does NOT contain)

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