How to use portion of a filename as Folder Name

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

Moderator: Mr_Noodle

How to use portion of a filename as Folder Name Thu Mar 29, 2012 2:25 am • by fwlun
Hi, I am new to Hazel (less than 1 day use). How do I use only portion of a filename as a criteria? That is can I use wildcard to ignore some portion of my filename? e.g. My filename is "2012noodlesoftapps.pdf". I want to create a subfolder using just "2012-apps" extracted from the filename as my subfolder name. How can I do that as I am not familiar with wildcard usage in Mac. Thanks.
fwlun
 
Posts: 6
Joined: Thu Mar 29, 2012 2:17 am

Look up "match pattern" in the help. That should show you what you need. Post here if you are having specific problems with it.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Hi, Mr. Noodle:

Thanks for your reply. With regard to your suggestions to read that Matching Pattern. I in fact found some article in this Forum who referred me to that article before my Post. I read through it many times and even tried to follow the suggestions how to setup the match pattern. I still could not extract portion of my original filename as the name of the sub-folder I was trying to create from the rules. For example, my filename is:

RCT-20120223-01.pdf
RCT-20120223-02.pdf
RCT-20120225-01.pdf
RCT-20120302-01.pdf
..... etc.

I have a list of files in this same naming structure. The only thing that changed are the last two sets of numbers. As you can see from this one that those are the dates along with sequence number. So I need to split those files into sub-folders by year-month (i.e. 2012-02, 2012-03, ..., etc.) using Hazel rules.

When I constructed the rule as: (...)(1)(1)(1)(1)(1)(1)(1)(...), it just replicated each name and use that as a sub-folder and move the corresponding file into this subfolder. So I ended up with one file per subfolder.

My intention is to create the subfolder as: 2012-02 and everything having RCT-201202xx-xx will be moved into this subfolder.

May be I did not understand the explanation in the Matching Pattern instruction. I could not find anywhere there may be specific examples similar to my case. I can however use the File Creation date and that works. But those dates are different than the date in my Filename. So I could not use these attributes. I hope you understand my difficulty. Thanks.

P.S. I am still evaluating your application as I am not sure if it will do what I want. You may not find my registration record since I am still on trial run just as of yesterday.
fwlun
 
Posts: 6
Joined: Thu Mar 29, 2012 2:17 am

Pattern matching for sorting needs to use "custom" tokens. That way we can group patterns, name them, and tell Hazel to sort your file in special ways.

This is what I'd do:

Code: Select all
if (all) of the following conditions are met for the (current file or folder)
   (Name) [matches] (Custom Token Matching Prefix)-(Custom Token Matching Middle)-(Custom Token Matching Suffix)

Then do the following:
   (Sort into Subfolder) with pattern (Custom Token Matching Prefix)-(Custom Token Matching Suffix)


Now, in order to create these custom tokens, drag "custom •" to the naming field. A new floating window will show and you'll assign it both a name and a pattern. The name is what is showing in my example above: "Custom Token Matching Prefix", etc. You can name these different tokens whatever you want.

The pattern is more important. Your pattern of (1)(1)(1)(1)(1)(1)(1)(1) would work fine, but you could also use (123) instead, which matches a number instead of a digit. Your patterns of (...) work fine too, but it looks like the suffix is always a number and the prefix is always letters. Here, we're going to separate the patterns into the three named tokens:

Custom Token Matching Prefix = (abc)
Custom Token Matching Middle = (123)
Custom Token Matching Suffix = (123)

Then, be sure to place dashes between prefix-middle-suffix because that helps to define the expected pattern for Hazel.

Hope this helps to clarify!
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Hi, Thanks for your detail reply and explanation.

There is still one point which is not clear to me.

In your example you have created the custom token: prefix-MIDDLE-suffix and applied this to my specific case as in one of the files (RCT-20120203-01) this will be:

prefix = RCT
MIDDLE = 20120203
suffix = 01

That is fine and all the files in the folder will in fact have this pattern.

But what I really want is to only select the first six digits (e.g. 201202) of the MIDDLE and reformat it into:

"2012-02" as a subfolder and then moves all files with the same first six digits into it.

Similarly for files with first six digits as "201203" will be moved into subfolder "2012-03", etc.

So my difficulty here is how to breakup the match pattern (e.g. MIDDLE with 8 digits) and select among them some digits (e.g. 4 digits and 2 digits) and then form a new pattern?

This is the part where I had trouble with how to write the rule. I appreciate if you can provide me with a specific that can do above. I think we are getting very close to solve this problem I have. Thank you very much.

By the way is there anywhere a documentation with good examples on how to write the rules? I found the explanation on "Match Pattern" is too brief for a rookie like myself to be able to learn from it.
fwlun
 
Posts: 6
Joined: Thu Mar 29, 2012 2:17 am

You can create two custom tokens and set them adjacent. Set one to four digits (1)(1)(1)(1), and the second to two (1)(1). Then create a third with (...) to catch the day.

That'll work.

I'm away from the computer, so if this is unclear let me know and I'll find time to clarify further.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Hi, Thanks again for your advice.

I had no problem trying to get the first 4 digits as you suggested but I had trouble understanding how to do the second portion which is the two digits. In other words how do I write the rule to skip the first 4 digits and pick up the next adjacent 2 digits?

If I write the rule as (1)(1), wouldn't it pick up the first 2 digits again and not skipping the first 4 and pick up the next 2? As the entire MIDDLE token has 8 digits from which I want to extract the first 4 and also the next 2 digits as separate token in order to be able to format them as Year token and Month token for the name of the subfolder.

I am sorry for keep asking this question but my problem is with this last hurdle. Thanks again.
fwlun
 
Posts: 6
Joined: Thu Mar 29, 2012 2:17 am

Both of these digit series are custom tokens. Create on custom token with four digits, create the second custom token with two digits. Then, because they are named, you can use the year and month as variables in the "actions" section of the rule.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Hi, I am sorry I still have problem understanding how to create the rule to pick up the 2 digits. I read through all the Help and discussion related to Match Pattern, there is nothing similar to what I need.

May be let me use another simple example to explain my difficulty:

Let say this is the file name: 20120324.pdf

How do I write a custom token to pick up "03" in above example to use as name of my subfolder? Please note that this "03" changed depending on the name of the file. It ranges from "01" to "12".

I hope this help you to understand my question.
fwlun
 
Posts: 6
Joined: Thu Mar 29, 2012 2:17 am

When I say "custom tokens" I literally mean using the (Custom •) token in the matching field:

Image

Image

Image
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Hi, Thanks for your illustration. It helped a lot but took me a while to figure out what you were saying there. At first I thought it was two steps. After experimenting for quite a while, I then realized that you are telling me to create both custom token at the same time rather than two steps.

Is there somewhere there is a good documentation on how to set these rules? I read the help within Hazel but those are very brief and difficult for a beginner like me to grasp what they are explaining, especially lack of good examples to illustrate.

Thanks anyway. At least I got to what I need. I decide to proceed to purchase this great software.
fwlun
 
Posts: 6
Joined: Thu Mar 29, 2012 2:17 am

I was trying to figure out something similar using custom tokens. I wanted to parse file names, then create create sub folders based on parts of filenames. Created date would not work as the files were new , but the dates used in the file names were in the past. I made a short video to help me remember the setup. You can see it at http://www.jamieshiller.com/2012/05/29/auto-sort-files-into-sub-folders-with-hazel/. Hope it helps :)
jshiller
 
Posts: 1
Joined: Mon May 28, 2012 11:27 pm


Return to Support