#1 2021-02-14 17:53

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 38

Script request: Remove left-part, if over long file name

I haven't visited the forum in a while.  I hope everyone is in good spirits during these long quarantine days. 

My scenario:   I have a bunch of ebooks that have long file names.  Mostly they are in the form of

"author1, author2, author3, author4, author5 - Really long name of book is here"

Many are over 256 characters long, which causes problems with windows.  I don't know if ReNamer is able to work with these types of files, but I'd like to do a bulk-rename.  The rule:

If length of file name > 256 chars, then rename that file. 
When renaming, keep name of book, but remove authors and deliminator. 
*Assume that authors are at the left of the deliminator.
*Deliminator = " - " (i.e. space dash space)

Thoughts?  -Steve

Offline

#2 2021-02-14 18:23

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 38

Re: Script request: Remove left-part, if over long file name

Actually, I found a work-around....   I realized that I can add a "Length" column in my file explorer.  I can sort by length, then use ReNamer to rename only the needed items.

Offline

#3 2021-02-15 19:40

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Script request: Remove left-part, if over long file name

The pascal script below should do the job:

const
  MaxFileNameLength = 255;
begin
  if Length(FileName) > MaxFileNameLength then
  begin
    FileName := ReplaceRegEx(FileName, '\A(.*?) - (.*)\Z', '$2', False, True);
  end;
end.

You can adjust the MaxFileNameLength constant as you see fit.

Alternatively, if you pre-filter the files and only have those exceeding the desired length, then you can just apply the Regular Expressions rule.

Offline

Board footer

Powered by FluxBB