crop files where path and filename length exceed 180 chars

Post any Bulk Rename Utility support requirements here. Open to all registered users.

crop files where path and filename length exceed 180 chars

Postby DJKR » Fri Apr 09, 2021 2:42 am

Hello,

Is it possible to crop all file names so that the total length of the path and filename do not exceed 180 characters.

Thanks and Regards
DJKR
 
Posts: 1
Joined: Fri Apr 09, 2021 2:37 am

Re: crop files where path and filename length exceed 180 chars

Postby Luuk » Fri Apr 09, 2021 10:14 am

Im thinking only javascript can conduct both folder-paths and file-names using the same number?
There is Filters(12) with checkmarks only in "Files" and "Subfolder", so then using the PathMin=181.
But this only uses 181 to present the files, not to rename them.

Im certain the javascript does this, because Im tested with... newName=object("folder")+name
And it presents the whole filepathname.ext, so you could set a variable==object("folder")+name, and then do the math.
Its unfortunate, but I cannot conduct this logic inside the javascript, so this is an exiftool example using regex to shorten the names.

exiftool -q -r -ext * -fast4 -if "$FilePath=~/.{181}/" -p "${FilePath; s/(.*)(\.[^.\\]+)$/$2|$1/; s/(.{181}).*/$1/; s/(.*)\|(.*)/$2$1/; s/(.{180}).*/$1/}" . 2>nul
This only presents what the new names would look like, but its very easy to change for renaming, or creating backups, etc.
Im including it to describe the logic, so then hoping an expert might convert this logic into the javascript!

The -if uses a filter to only conduct FullPathNames with 181-or-more characters.
The first s/// converts Full/Path/Name.ext ===> .ext|Full/Path/Name (in case of different length .extensions).
The next s/// destoys the 182nd-or-more chars (keeping 181 because | still separating the .extension).
The next s/// converts .ext|Full/Path/Name ===> Full/Path/Name.ext so now its exactly 180-characters.
The last s/// converts any filenames that were missing an .extension.

Its not renaming anything, because only using -p "${FilePath; instead of -FileName"<${FilePath;
Hopefully, there can be some experts to convert this logic into javascript code, or maybe the javascript grants a much simpler way?
If nothing else, Im sure there is also gui applications to conduct this also, but Im not ever experimented with any.
Luuk
 
Posts: 691
Joined: Fri Feb 21, 2020 10:58 pm

Re: crop files where path and filename length exceed 180 chars

Postby therube » Fri Apr 09, 2021 4:10 pm

Everything can easily find your 180's.
Do a search for: path:len:>180 (or path:len:>254...).

BRU kind of requires (sub)directories to be within the same parent in order to work with them.
If they are, & if the directory parts have long path sections, even better if they're somewhat randomized, then you could do something like:
Code: Select all
1:RegEx, v2
Match:  (...).*
Replace:  \1

12:Filters -> Folders

and that would truncate the path sections down, so something like:
Code: Select all
01fd92953195e11e7ea7d7ec10beb523_99bd27c5-267a-4734-b71e-4d1fa548bc2a
WER9AE0.tmp.WERInternalMetadata.xml
amd64_microsoft-windows-d..pwindowmanager-core_31bf3856ad364e35_6.1.7601.23403

becomes:
Code: Select all
01f
WER
amd
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: crop files where path and filename length exceed 180 chars

Postby BogStandard » Tue Apr 13, 2021 12:01 pm

I agree with therube's suggestion to use Everything. I use it as a complimentary programme to BRU.

I have well over a dozen Everything 'Bookmarks' (predefined query patterns) that I run looking in locations for filenames that do not conform to my preferred formats. It is then an easy select and drag'n'drop into BRU, that is already loaded with my rename pattern, to rename the files to my standardised format.

Regards...
BogStandard
 
Posts: 17
Joined: Sun Feb 07, 2021 11:25 pm


Return to BRU Support


cron