Page 1 of 1

Sort into Subfolder using part of filename

PostPosted: 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.

Re: Sort into Subfolder using part of filename

PostPosted: Mon Feb 22, 2021 10:22 am
by Mr_Noodle
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.

Re: Sort into Subfolder using part of filename

PostPosted: 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?

Re: Sort into Subfolder using part of filename

PostPosted: Mon Mar 01, 2021 11:32 am
by Mr_Noodle
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.

Re: Sort into Subfolder using part of filename

PostPosted: 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!

Re: Sort into Subfolder using part of filename

PostPosted: 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

Re: Sort into Subfolder using part of filename

PostPosted: Fri Jan 07, 2022 10:23 am
by Mr_Noodle
Can you post the pattern you are using for Sort into subfolder?

Re: Sort into Subfolder using part of filename

PostPosted: 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

Re: Sort into Subfolder using part of filename

PostPosted: 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