Sort into Subfolder using part of filename

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

Moderator: Mr_Noodle

Sort into Subfolder using part of filename Fri Feb 19, 2021 2:00 pm • by jdd
Hi all! I have found this answered a few different times, but I'm still struggling to understand how this works.
I'm pretty good with Hazel usually, but I was expecting this to work by 'capturing' a part of the filename (like batch Renaming works with GREP/Regex).

My aim is to have these files:
Code: Select all
window-meteor storm_LOOP_#[840,840].png
house-garden_IN_#[840,840] copy.png
house-wall_#[840,840] copy.png
window-meteor storm_IN_#[840,840].png
tree-leaves blowing_#[940,400].png


Sort like this:
Code: Select all
window_
     window-meteor storm_LOOP_#[840,840].png
     window-meteor storm_IN_#[840,840].png
house_
     house-garden_IN_#[840,840] copy.png
     house-wall_#[840,840] copy.png
tree_
     tree-leaves blowing_#[940,400].png


Other answers from Mr. Noodle mention using Name > Matches, but I don't see how I can use the pattern (or part of the pattern) to sort into subfolders? I can create my own long list of potential folder names (like a mega long if/else function) but obviously that's too manual for me!

Any help would be great! Thanks.
jdd
 
Posts: 7
Joined: Thu Aug 25, 2016 6:27 pm

How do you determine what you need to grab? Your examples show everything up to the first dash. If that's the case, you can make a pattern to match that. Otherwise, you can use a list if you need to match a specific set of words.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Sort into Subfolder using part of filename Sun Feb 28, 2021 6:34 am • by jdd
Mr_Noodle wrote:How do you determine what you need to grab? Your examples show everything up to the first dash.


Exactly – I want to grab everything before the first dash. I don't know what future filenames there will be, so creating a specific list of words would require constant updates.

My instinct is to use [Sort into subfolder] with pattern: [name], but how do I make [name] choose only the first word?
jdd
 
Posts: 7
Joined: Thu Aug 25, 2016 6:27 pm

If there's always a dash, then try using a custom attribute to match everything up to the dash and use that in the Sort into subfolder pattern. Look up match patterns in the manual if you are unfamiliar with them.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Sort into Subfolder using part of filename Tue Mar 02, 2021 7:53 am • by jdd
For anyone else making the same mistake as me:
Image


To use Sort into Subfolder with a pattern using a custom attribute, you must first create that custom attribute in the conditions.
Image

Then a new section below the standard Match Pattern tokens will appear, and your custom attribute will be available there.

Seems obvious now, but I guess if there was a section labelled Custom Attributes below the standard tokens (but it was empty) I might've pieced two and two together!

Thank you for the help, MN!
jdd
 
Posts: 7
Joined: Thu Aug 25, 2016 6:27 pm

Re: Sort into Subfolder using part of filename Thu Jan 06, 2022 11:52 am • by cortig
I’m coming back to this older thread which corresponds exactly to what I have been trying to do, but I’m struggling with one specific aspect:
It works perfectly if the subfolder already exists, but I can’t find a way to have Hazel create the subfolder where to sort the files if it didn’t already exist… It might be basic, but I can’t find out how to do it. Hazel always returns an error telling me the destination doesn’t exist.

Any suggestion?

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

Can you post the pattern you are using for Sort into subfolder?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Sort into Subfolder using part of filename Fri Jan 07, 2022 12:23 pm • by cortig
Mr_Noodle wrote:Can you post the pattern you are using for Sort into subfolder?


The files I want to sort all begin with a text tag that looks like that: [whatever]

I would like all the [some_tag] files to go in a "[some_tag]” subfolder, the [some_other_tag] files to go in a "[some_other_tag]” subfolder etc. Whether the subfolder already exists or not (in which case it needs to be created obviously).

sort:
    [something] whatever
    [something] another name
into a subfolder: [something]

sort:
    [someotherthing] whatever
    [someotherthing] whatever else
    [someotherthing] whatever yet another thing
into a subfolder [someotherthing] (which doesn’t yet exist and needs to be created in the process)

It’s not very different from the case presented her, except that some of the subfolders don’t necessarily pre-exist.

And actually, even with the folders existing, I’m still struggling a bit: I can’t seem to find a way to get Hazel to use the pattern or the match to be used for the subfolders (I’m still frantically reading through the documentation to see how to do it with custom attributes as illustrated in this thread).

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am

Re: Sort into Subfolder using part of filename Sat Jan 08, 2022 7:52 pm • by cortig
cortig wrote:It’s not very different from the case presented her, except that some of the subfolders don’t necessarily pre-exist.


Well, it looks like you can dismiss my request… I have no idea what I might have done before that made it error, but I re-created the pattern again today, and it worked like a charm!
The custom text pattern detected the proper text tag at the beginning, and the action created the folders when they were missing!

I can’t believe how much I struggled with it before it just… worked, when I recreated it.
Hazel then sorted out my >850 files in a flash :D

Corentin
cortig
 
Posts: 17
Joined: Thu Jan 06, 2022 11:49 am


Return to Support

cron