Matching PART of file names

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Matching PART of file names Sat Jun 02, 2012 11:50 pm • by shantastik
Hello;

Is is possible to do the following?

I have a lots of files (thousands) in a folder. They are of this format

Photo1014135-1.jpeg
Photo1014135-2.jpeg
Photo1014135-3.jpeg

What I want to do is create a folder for the part of the name before the DASH-#-.jpeg and move any file names into it. So for examples above I want to move those 3 files into a folder named Photo1014135

For each "name" where name is "Photo1014135" there is a variable number of photos from 1 - 25
So some folders would need to have 25 images moved into them, some just 1 -- it just depends on the images.

Is it possible to have HAZEL look at the file name up and until the dash?

Thanks
shantastik
 
Posts: 1
Joined: Sat Jun 02, 2012 11:46 pm

Re: Matching PART of file names Mon Jun 04, 2012 2:43 pm • by a_freyer
Yup - and its actually called Matching. There are many threads on this forum regarding matching but the basic idea is to tokenize a known file naming convention.

I'd use custom (•) tokens like this:

Code: Select all
if (all) of the following are true (for the current file or folder)
     if name matches (photo name•)-(suffix•)

then
    rename file (suffix •)
    sort into subfolder (photo name •)



The result is this:

Photo1014135-1.jpeg
Photo1014135-2.jpeg
Photo1014135-3.jpeg
Photo1014136-1.jpeg
Photo1014136-2.jpeg
Photo1014136-3.jpeg

/Photo1014135/
1.jpeg
2.jpeg
3.jpeg


/Photo1014136/
1.jpeg
2.jpeg
3.jpeg



To do this, create a "matching" rule and drag a custom token into the input box. A new box will show where eyou can type this: Photo(12) where the (12) is a numerical token dragged from the selection field below.

Close this token naming it "photo name" and do the same with suffix, dragging only (12) into the pattern input area.

We're using custom tokens here so that we can rename the files. If you just dragged (12) to the "name matches" area, then Hazel would not be able to use the match in later actions on the file.

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


Return to Tips & Tricks - DO NOT POST QUESTIONS