Trim chars from filename

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

Moderator: Mr_Noodle

Trim chars from filename Thu Jul 20, 2017 2:17 pm • by svh1985
Hi,

I have setup some rules to monitor my download folder for invoices.
Each rule matches on partial filename for a specific supplier and moves it to a specified folder.

But some of these suppliers prefix their PDF files: "Invoice 134.pdf" and I would like to rename the file to "134.pdf" after it has been moved.

I have successfully automated the movement of the PDF files with Hazel, but I still need to rename the files manually with a separate tool:
Image

But I would love to automate that last part too.

Is this possible with Hazel or do I need to create custom scripts to accomplish this?

Thanks!
svh1985
 
Posts: 10
Joined: Fri Jan 20, 2017 12:49 pm

Re: Trim chars from filename Thu Jul 20, 2017 3:37 pm • by Mr_Noodle
Search for "match patterns" in the help. You can set up a custom attribute to match the part you want to keep and then use that in a Rename pattern.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Trim chars from filename Thu Oct 17, 2019 10:44 am • by ruiguerreiro
Mr_Noodle wrote:Search for "match patterns" in the help. You can set up a custom attribute to match the part you want to keep and then use that in a Rename pattern.


Hi there,
Would you mind going over the specifics of it, please? I'm going crazy trying to figure this out. Here's an example of a filename I want to change:

NL 20190901010101.pdf

I need it to remove the start of the name "NL ", remove the last 8 digits before the file extension, ending up with the filename "201909.pdf".
The first part is easy, I simply add a "Rename" step and configure it to replace "NL " with nothing. The second part, however, I simply can't figure out how to do. I know you mentioned "match patterns" but after reading through the help file, I still don't understand what I should be doing.

Thank you so much!
Rui
ruiguerreiro
 
Posts: 11
Joined: Thu Oct 17, 2019 10:35 am

Re: Trim chars from filename Thu Oct 17, 2019 4:07 pm • by Mr_Noodle
Create a pattern to match the name. The part you want to keep, save that into a custom attribute. You can then use that in the rename pattern.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Trim chars from filename Fri Oct 18, 2019 3:27 am • by ruiguerreiro
Mr_Noodle wrote:Create a pattern to match the name. The part you want to keep, save that into a custom attribute. You can then use that in the rename pattern.


Thank you for getting back to me so quickly. I'm afraid I don't get it, though.

How do I create a pattern to match the name? And how do I save it into a custom attribute? The thing is, the part I want to keep, changes every month, as it's a date, so what I want to tell Hazel is to keep 6 characters of the original name, starting on character 4 up t0 character 9, regardless of what they are.

Sorry to be a pain in the ass with all these questions. Thank you so much for your patience.

All the best,
Rui
ruiguerreiro
 
Posts: 11
Joined: Thu Oct 17, 2019 10:35 am

Re: Trim chars from filename Fri Oct 18, 2019 5:59 am • by ruiguerreiro
I think I got it :) After a bit of trial and error I figure it out.

Thank you so much anyway.
ruiguerreiro
 
Posts: 11
Joined: Thu Oct 17, 2019 10:35 am

Re: Trim chars from filename Fri Oct 18, 2019 7:24 am • by Trickyt57
Here you are in images:
Image

Image

Image
Trickyt57
 
Posts: 55
Joined: Tue Sep 18, 2018 12:17 am

Re: Trim chars from filename Fri Oct 18, 2019 10:21 am • by Mr_Noodle
@Trickyt57: I don't think that quite address the issue here. I believe the beginning text may change and that they just want to extract the specific digits after that (but before the last 8). For that, you really do need to use match patterns.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Trim chars from filename Sat Oct 19, 2019 3:25 am • by ruiguerreiro
Hi and thank you for all the input.
I figured out how to do it. Using a match pattern for the Date, I was able to do it. Once you understand how it works it's actually pretty easy.
In my case, I simply used the "Custom Date" option, typed it exactly how it shows in my invoice (18 Sep 2019) and then used the same string in the Rename rule bellow. The only other change needed, if you want it, is to edit the Date Pattern (I turned mine into 201909).
Hope it helps someone looking to do the same.
ruiguerreiro
 
Posts: 11
Joined: Thu Oct 17, 2019 10:35 am


Return to Support