Truncate Filename?

All about user-defined episode / movie / file name format expressions
Post Reply
DevXen
Power User
Posts: 164
Joined: 12 Oct 2014, 21:15

Truncate Filename?

Post by DevXen »

Is there a way to limit the characters that it renames the file too? - So if it's over the 256 Character limit (with folder path) it'll cut off the necessary characters at the end, so it'll fit? - it'd be better to cut off at the word level, instead of character, so words aren't cut in half, but i'm not sure if that's possible.


As i've never had a media server, find valid/correct info. especially when it comes to DVD Extras, it generally marks every file as being that movie, so when you look for that movie, it can have 50 listings, with no way to tell what one it is. - I got tired of that, and quit using the media servers scraping. as there has been no way to skip, or ignore them, that i've found in any, yet.

So because of this, i'm putting all the info i need/want in the filename, which is making them pretty long. but only on a few so far, has it had an issue with being to long. and as the last bit of info i have is the top 3 genres of the movie, it'll be okay to cut one or two of them out so the filename/path isn't too long.. I'm just not sure if Filebot can do this.


Thanks,
-Dev
User avatar
rednoah
The Source
Posts: 22975
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Truncate Filename?

Post by rednoah »

{n} - {s00e00} - {e} style format limited to 5 characters:

Code: Select all

{allOf{n}{s00e00}{e}.join(' - ').take(5)}
The only tricky part is that you can't use multiple {expressions} because then you can't track how long your String is. But if you only use a single {expression} then you can do whatever you want and you always check how long the output String is already.

e.g. as for splitting by words, i'm sure you'll figure it out:

Code: Select all

{'a word'.split(/\W/).inject{ s, i -> def n=s+' '+i; n.length() > 5 ? s : n}}
:idea: Please read the FAQ and How to Request Help.
DevXen
Power User
Posts: 164
Joined: 12 Oct 2014, 21:15

Re: Truncate Filename?

Post by DevXen »

Ok, i'll work with that and see what i can do, thank you.
User avatar
rednoah
The Source
Posts: 22975
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Truncate Filename?

Post by rednoah »

I've added String.truncate(limit, pattern) with r3096 to simplify this kind of format.

e.g.

Code: Select all

{'a word'.truncate(5, /\s/)}
:idea: Please read the FAQ and How to Request Help.
Post Reply