Rename based on variable file name

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

Moderator: Mr_Noodle

Rename based on variable file name Mon Oct 20, 2014 12:36 pm • by brijazz
I have files added to a watched folder; when they are added, they'll look something like this:

Workbook.719.username.txt

I would like for them to be renamed as something like this:

Workbook.Chapter7Unit19.username.txt

The catch is that I don't know what the three-digit string will be when a file is added; it could be any combination of numbers. Futhermore, "Workbook" is not always at the beginning; it could be any word(s) as well. How can I get Hazel to look for a three digit string, remember what it is, and then insert "Chapter" and "Unit" at the desired place within the string?
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename based on variable file name Mon Oct 20, 2014 1:49 pm • by Mr_Noodle
Search the help for match patterns. You can set up separate custom attributes to match the first digit and then the next two so you can then split them up when renaming.
Mr_Noodle
Site Admin
 
Posts: 11866
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename based on variable file name Mon Oct 20, 2014 3:45 pm • by brijazz
Mr_Noodle wrote:Search the help for match patterns. You can set up separate custom attributes to match the first digit and then the next two so you can then split them up when renaming.


Thanks, that's a great function. I got CLOSE, but it's not perfect. I ended up with a file that looks like:

Workbook.719.username.Chapter7Unit19.txt

So, I was able to split the three digits into two groups, prepend my desired text to each group and insert them into the filename. But how can I remove the *original* part of the filename (the part that reads "719" in this example). I have a feeling I'm missing something easy here!
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename based on variable file name Mon Oct 20, 2014 4:19 pm • by Mr_Noodle
Are you using "name" in your rename pattern? If so, that just includes everything. You'll need to use custom attributes to capture the text before and after and then shuffle them all as you see fit in the rename pattern.
Mr_Noodle
Site Admin
 
Posts: 11866
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename based on variable file name Mon Oct 20, 2014 6:10 pm • by brijazz
Mr_Noodle wrote:You'll need to use custom attributes to capture the text before


That's where I'm having trouble (read: help!). If every incoming file had the same number of words at the beginning, I think I could work out a solution.... but that's not the case.

File #1 might look like: Workbook.719.username.txt
File #2 might look like: Case.Study.813.sample.username.txt

...and so on. Given the variations between file names, can I still get a match?
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename based on variable file name Tue Oct 21, 2014 3:02 pm • by Mr_Noodle
How about using the "anything" token?
Mr_Noodle
Site Admin
 
Posts: 11866
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rename based on variable file name Tue Oct 21, 2014 4:35 pm • by brijazz
Mr_Noodle wrote:How about using the "anything" token?


Well, of course :roll:

It's taken me a minute to wrap my head around match patterns, but I think I've got it. Thanks for pointing me in the right direction.... Hazel support has always been great!
brijazz
 
Posts: 21
Joined: Sun Mar 08, 2009 9:07 am

Re: Rename based on variable file name Thu Oct 30, 2014 9:44 pm • by countrymom
So don't use NAME in renaming? Use (...)?

How does that strip off the original name?
countrymom
 
Posts: 8
Joined: Tue Oct 28, 2014 9:41 pm

Re: Rename based on variable file name Fri Oct 31, 2014 11:59 am • by Mr_Noodle
He doesn't care about the stuff up until the number. He captures the number into a custom attribute but everything before it can be thrown out so he uses (...) to match all that stuff. Since it isn't used in a custom attribute, that text is not used again.
Mr_Noodle
Site Admin
 
Posts: 11866
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support