How can I trim a filename to a certain number of characters?

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

Moderator: Mr_Noodle

I need to setup a rule that checks if a filename is longer then 250 characters (any), and if it is, it should trim the filename to a max of the first 250 characters. How could I do that?
mabebi
 
Posts: 9
Joined: Sat Jan 15, 2022 6:14 am

There is no built-in action to do that yet. You'd probably need a script for that part. It is on the feature list as something to consider in the future. Can you supply more details in why you need this?
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

For my photos, music and documents, which come from various sources, I have build quite a huge Hazel workflow automatically renaming, sorting and archiving the files into directories. I have a multi platform environment (MacOS, Linux, iOS, Windows, some cloud services and NAS to access the files and I have issues in Hazel to process the files when the filename is longer then 254 characters.

In short: Its a rule I want to check the integrity of filenames and folder names to not be longer than that. I already do that to allow only certain characters but limiting the number of characters seems to be a bit harder.
mabebi
 
Posts: 9
Joined: Sat Jan 15, 2022 6:14 am

Thanks. It's something already in the feature database and will consider this a vote for the feature. One question though: suppose you truncate the filename and it ends up clashing with a file that is already there. How would you want that dealt with?
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Maybe some options:

- truncate one or more character(s)
- add a counter or customcharacters
- overwrite filename
- skip leave filename untouched
mabebi
 
Posts: 9
Joined: Sat Jan 15, 2022 6:14 am


Return to Support

cron