Renaming horrible file names with irregular patterns

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

Moderator: Mr_Noodle

Hello,

I have a lot of .docx and .pdf files that have horrible names. Part given by each the author (one file per author) and part by a server.

E.g∵

123456 - Fred Bloggs Fred_Bloggs_CODE1234_XYZ.pdf
I want it to be:

Fred Bloggs.pdf

123456 will vary from file to file but has the same number of integers.
The author's name is always duplicated with underscore separations
CODE1234 is the same on every file.
_XYZ is a title that the author has given. It's almost always text but varies from file to file.

I know that I can iteratively scoop out all the numbers and the ' - ' and the CODE1234 but I'm struggling to see how I can:

1. Get rid of _XYZ (without having 26 replace a-z → blank, which would be pretty annoying!)
2. Get rid of the duplicate " Fred_Bloggs_" name format.

I know that I can use the "#" numbers/letters counter to act on a sequence with any number of numbers/letters. I thought that I could use something like " #_#_" to get rid of " Fred_Bloggs_" but it removes letters from parts of the file names that are not in-between the space and the underscore.

I could shave off the initial junk with the rules that I have to begin file names correctly. Is it possible to rename as ONLY the first 2 or 3 words of the bad file name. Apart from having some names with more than 2 parts, this would be a good fix.

Any ideas, please? TIA!
TobyEmoji
 
Posts: 3
Joined: Thu Apr 02, 2020 9:46 am

First, please do not post Hazel questions in the Forums/Site discussion. That forum is for discussions about this site/forums.

Look up match patterns in the manual. You can use a pattern with custom attributes to match the parts of the name you want to preserve. You can then use that custom attribute in the Rename pattern.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron