Page 1 of 1

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

PostPosted: Sun Sep 18, 2022 4:20 am
by mabebi
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?

Re: How can I trim a filename to a certain number of charact

PostPosted: Mon Sep 19, 2022 9:44 am
by Mr_Noodle
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?

Re: How can I trim a filename to a certain number of charact

PostPosted: Sat Sep 24, 2022 3:13 am
by mabebi
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.

Re: How can I trim a filename to a certain number of charact

PostPosted: Mon Sep 26, 2022 9:40 am
by Mr_Noodle
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?

Re: How can I trim a filename to a certain number of charact

PostPosted: Sun Oct 23, 2022 5:00 pm
by mabebi
Maybe some options:

- truncate one or more character(s)
- add a counter or customcharacters
- overwrite filename
- skip leave filename untouched