rename folder to (filename of an inclusive file)

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

Moderator: Mr_Noodle

Hi:

Will I need to work out an apple script to do this?

Rename folder to filename of one of the inclusive files less the last 8 characters. The file to use is identified by its extension.
The folder has 3 or 4 files.

BEFORE
Folder name = AAABB_
name of file within folder "AAABB_" = happy it worked out_AAABBzzzzyyyy.EXT

AFTER
Renamed folder name = happy it worked out_AAABB

Thankyou for the direction/guidance/
NoodleNewbie
 
Posts: 34
Joined: Fri Jul 13, 2018 5:17 pm

I think you can do it with match patterns and a nested condition. Something like:
Code: Select all
   If (all) are met
      Folder name is <<whatever>>
      If (all) are met for (any of its sub-files)
         Name matches (• file name)(character)(character)(character)(character)(character)(character)(character)(character)
   Do
      Rename (• file name)

where (• file name) is a custom attribute which you create to match anything. The overall pattern will match everything but the last 8 characters.

You may need to tweak the above depending on the specifics of your case but that should give you a start.
Mr_Noodle
Site Admin
 
Posts: 11230
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Very nice thinking! Using a dummy variable(Hazel attribute, custom token) to hold the filename, so then can use it rename the folder. Thankyou Mr. Noodle.


here it is , just in case, it helps others.


Hazel Rule
1 Select file with the desired filename (e.g. extension = XXX) Rename Folder (this file is 1 of 4 files within the folder)
2 Rename folder using the desired filename
Image


where Filename is a Custom Token
Set Custom Token to Anything (...) as we can select the desired filename by the file unique extension
Image
NoodleNewbie
 
Posts: 34
Joined: Fri Jul 13, 2018 5:17 pm


Return to Support