#1 2017-10-19 22:09

petulawilcox
Member
Registered: 2017-10-19
Posts: 2

Deleting varying length sections from the middle of filenames

Hi,

I have a folder and subfolders with several thousand files, a lot of them with very long names. I would like to get all the files with names longer than 148 characters and cut them down to 148 characters so that the new filename would consist of the first 100 and last 48 characters of the original.

This can't be done without some scripting, I'm afraid, and since I'm unfamiliar with that, I would highly appreciate your help.

Offline

#2 2017-10-20 09:16

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Deleting varying length sections from the middle of filenames

Hi and welcome.


FROM:
148+.ext
A 1234567890.ext
B 12345678901234567890.ext
C 123456789012345678901234567890.ext
D 1234567890123456789012345678901234567890.ext
E 12345678901234567890123456789012345678901234567890.ext


TO:
100 # 48.ext
A 1234567890.ext
B 12345678901234567890.ext
C 123456789012345678 # 567890.ext
D 123456789012345678 # 567890.ext
E 123456789012345678 # 567890.ext
My Rule for that above renaming: Regular Expressions: Replace expression "^(.{20}).+(.{6})$" with "$1 # $2" (skip extension)



Try:
Regular Expressions
Expression: ^(.{100}).+(.{48})$
Replace: $1 # $2
(skip extension)

Also check options "fix conflicting new names" if you get files with same name after shortening.
12345678901234567890 # 567890.ext
12345678901234567890 # 567890 (2).ext
12345678901234567890 # 567890 (3).ext



Explanation:

^(.{100}).+(.{48})$

^(.{100}) >>> will match 100 signs from begin and capture in (...) for reuse by '$1'
.+ >>> will match one-orAsManyAsPossible, untill
(.{48})$ >>> will match 48 signs at the end and capture in (...) for reuse by '$2'


So that will work on file name length of 100 + 1(or more) + 48 = 149(or more).
On shorter names the match will fail and the file is skipped.


As Replacement we concatenate a new string from both captures, $1 and $2.
Take a look at the preview!
Of course you can drop the ' # '-part from the replace, that is only for a good view what happens.


 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2017-10-20 19:41

petulawilcox
Member
Registered: 2017-10-19
Posts: 2

Re: Deleting varying length sections from the middle of filenames

Worked perfectly, thank you.

Offline

Board footer

Powered by FluxBB