Match a file name pattern and delete all similar files.

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Every PDF file on my hard disk starts with a six digit number, e.g. "025431 Bank statement dated 2019 10 31.pdf.

When Hazel finds a newly scanned PDF file, it gives it a unique name, preceded by the unique number.

The newly named file is then copied into six folders named according to the type of document (bills, bank statememnts, invoices, tax etc.), date, number, and so on, including backups.

Often a rule I have written is not precise enough. The file is wrongly named and filed in the six folders. I then have to improve my rule, and MANUALLY DELETE all six files. Manually updating is very tedious.

Instead, I would like to be able drop any one of the wrongly named files into a folder named "Badly named files", and have Hazel read the six-digit number. (So far no problem). Now I want Hazel to hunt down ALL files which start with the same six-digit number, and to move all those files to trash.

The last bit seems easy at first sight, but I can't seem to do it. I would need to write a rule something like this:
    If folder name "Badly named files" contains a file named {number}{anything}
    Do the following
    Move all files on the hard disk starting with {number} to trash

I have looked at loads of possible workarounds, but still can't figure out how to do this. I literally have more than 10'000 wrongly named files, so it is not a manual job, as I would need to delete 60'000 files scattered all across my hard drive in hundreds of folders.

Any ideas?
Trickyt57
 
Posts: 21
Joined: Tue Sep 18, 2018 12:17 am

Where is the original badly named filed in relation to the others? Also, have you considered using a smart folder?
Mr_Noodle
Site Admin
 
Posts: 8697
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Dear Mr Noodle,

Yes I already tried smart folders, but it does not work in the way I would like.

I have perhaps 1000 misnamed files with 6 copies of each scattered anywhere and everywhere on the hard disk in hundreds of folders. It is easy enough to delete one set of 6 manually by typing the six-digit part of the file-name as the criteria and then deleting everything which comes up manually. However I would need to repeat that exercise 1000 times. Likewise, I could select the files as I find them and tag them with yellow, and have Hazel delete everything tagged yellow. I would still need to tag six thousand files in random locations.

So what I am looking for is a Hazel function which will read the six digit part of a file name (easy to do that), and then to search for every file on the home folder and sub-folders of the hard drive with the same six digits as part of the file name and delete it. That sounds easy, but seems to be impossible to me.

Put another way if my home folder contains the file "012345 Taxes.pdf", then I would like to delete all files in other directories which have "012345" as part of their file name. That way, whenever I find a mis-named file I can simply drag it to the folder for deletions.
Trickyt57
 
Posts: 21
Joined: Tue Sep 18, 2018 12:17 am

I don't really think this is doable without writing a script. The file being match needs to be "close" to the original in the file hierarchy. If you can come up with a Smart Folder that identifies these folders, then you can use Hazel to monitor that.
Mr_Noodle
Site Admin
 
Posts: 8697
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support