Appending text to a file name

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

Moderator: Mr_Noodle

Appending text to a file name Tue Mar 20, 2012 4:16 pm • by myor
Hi
I am new to Hazel. I have the following challenge.

I want to change the name of a file when it arrives.
Format when it arrives: Name day.month.year.extension
My initial wished format: Name year.month.day.extension

This rule I manage to create.
However I want to add afterwards manually "contents" to arrive at
my wished final format: Name year.month.day contents.extension
without the contents being "erased" by a rule when reprocessed.

Question: what kind of solution can I use to accomplish this challenge (with your help)?

Thanks for your kind help.
Best regards,
Leif
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Wed Mar 21, 2012 10:51 am • by Mr_Noodle
Check the help for "match patterns". I believe that should do what you want.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Appending text to a file name Wed Mar 21, 2012 4:02 pm • by a_freyer
Specifically, I'd add a custom token with "ANYTHING" as its content - append that when you're renaming the file and you should be good to go.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Appending text to a file name Thu Mar 22, 2012 4:09 am • by myor
Unfortunately I do no understand your short message as I do not yet know the Hazel language. Could you show an example of "token with Anything". Where shall I put it? Why should I do it?
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Thu Mar 22, 2012 12:32 pm • by Mr_Noodle
I did get your email but I thought I'd respond here in case anyone else wants to know the answer.

When he says "custom token with anything", he means you drag in the custom token (•) and then in its pattern, drag in the "anything" token (...).

Also, it seems like you want to reorder the parts of the date. You need to create a custom token for each date part (year, month, day) so you can re-order them in the renaming pattern.

Code: Select all
 If name matches (•name)(•day).(•month).(•year)
 Rename (•name)(•year).(•month).(•day)(whatever else you want to add)

where:
  (•name) = (...)
  (•day) = (123)
  (•month) = (123)
  (•year) = (123)


You will probably have to tweak that but it gets the concepts across.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Appending text to a file name Fri Mar 23, 2012 4:08 am • by myor
That was much clearer. I'll try to reflect your efforts of explaining into a solution. Keep you posted.
Thanks!
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Tue Apr 10, 2012 5:24 pm • by myor
Having tried a few times to reconstruct the proposed patterns as below

If name matches (•name)(•day).(•month).(•year)
Rename (•name)(•year).(•month).(•day)(whatever else you want to add)

where:
(•name) = (...)
(•day) = (123)
(•month) = (123)
(•year) = (123)

I cannot add a whatever-token to line 2 without adding a token on the first line, i.e. I have to write
"If name matches (•name)(•day).(•month).(•year) (whatever else you want to add)"
to be able to have the full line:
"Rename (•name)(•year).(•month).(•day)(whatever else you want to add)"

But that is not what I need.

And if I remove from first line (whatever..) it is not available as a token on the renaming line.

So I got stuck.

Thanks for your help.
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Wed Apr 11, 2012 1:59 pm • by Mr_Noodle
I'm sorry, I don't follow. You don't have to add the (whatever else) part. I just stuck that in in case you wanted to add extra text to the end of the name. If the names only consist of the date, then omit that. Maybe if you provide an exact filename with examples of what it looks like before and and exactly how you want it to look after but now I don't see what the problem is.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Appending text to a file name Wed Apr 11, 2012 4:25 pm • by myor
Hi,
Thanks for your feedback. Here is the example:

Original file format: Le sens de l'info 03.04.2012.mp4
Adjusted file format with appended text at the end: Le sens de l'info 2012.04.03 Les Anges.mp4

I.e. I want to be able to add manually a text after the date has been changed by Hazel. When Hazel sees the file name with the appended text she shall ignore this file.

So my question is how to use the token function in this case as you outlined earlier.

Leif
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Thu Apr 12, 2012 11:41 am • by Mr_Noodle
Ah, I think the confusion is that I made the mistake of putting the "whatever" stuff in parentheses. It's not a token. I was just saying that you can just type in text in the rename pattern and that text will appear in the final name. So, in your case, just type "Les Anges" into the rename pattern where it's supposed to appear, in this case, at the end.

Don't add that text to the match pattern. It doesn't appear in the original, so it won't match.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Appending text to a file name Fri Apr 13, 2012 2:53 am • by myor
I must make a check.

You say: "So, in your case, just type "Les Anges" into the rename pattern where it's supposed to appear, in this case, at the end."
I said: "I want to be able to add manually a text after the date has been changed by Hazel. When Hazel sees the file name with the appended text she shall ignore this file."

Your wording indicate to me my wanting to put "Les Anges" (or whatever) into a formula (rename pattern). However, I want to insert it manually after the change was made by Hazel AND so that Hazel sees the appended text next time does not remove it! That was what happened when I first tried.

So:how to do it?
Thanks
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Mon Apr 16, 2012 11:53 am • by Mr_Noodle
Oh, I see. So, have one rule to rename (without the extra text). If you are adding the text yourself, then have another rule which ignores text that ends with "Les Ange". Something like:

If name ends with Les Anges, Ignore file

Or if you insist on only ignoring if it has the date pattern with the text at the end, just do the match pattern and type the text at the end of the pattern.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Appending text to a file name Tue Apr 17, 2012 9:09 am • by myor
Thanks for your kind support. This is how I got it to work. May be of interest to others:

If Name matches •title •day.•month.•year •additional text
Then Rename with pattern •title •year•month•day•additional text extension

I wanted to change the file names of an iTunes podcast folder. Now that was solved remains an annoying problem. The changed file names do not change i iTunes itself.

Does anyone have a clue?

Thanks
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Re: Appending text to a file name Tue Apr 17, 2012 4:44 pm • by Mr_Noodle
Are you referring to the track name in iTunes? That's a field stored in the file the file itself. You'd need to do a script to change that. Look up ID3 tags in Google.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Appending text to a file name Wed Apr 18, 2012 1:02 am • by myor
Problem is: I do not know how to write a script. Have never done it, though I was a programmer in the dark ages.
myor
 
Posts: 12
Joined: Tue Mar 20, 2012 4:04 pm

Next

Return to Support