How to Truncate FileNames

I have a directory full of long file names (some long enough that when copied to another directory they will exceed the character number limit). For various good reasons, I cannot shorten the directory names.

I NEED A WAY TO SHORTEN ALL FILE NAMES WITHIN A GIVEN DIRECTORY (keeping, of course, the file extension). Thus, for example, I might want to change all fines in a given directory so that the file name [the portion appearing before the file extension] is simply truncated so as not to exceed X [e.g., 25] characters.

I have TRIED to figure out how to do this with DOpus (and I am sure it can be done, because I constantly tell everyone, including readers of my columns in TechnoLawyer, that Directory Opus can do anything).

Right now, I am facing a pressing deadline for which I need the above information.

I will be eternally grateful if you can help me out (the sooner the better)!

Thank you.

Here you go. It will add a number and letter to ensure uniqueness. You can adjust the max length. See the comment inside the script.

abcdefghijklmnopqrstuvwxzy 1.txt => abcdefghijklmnopqrstuv_1a.txt
Truncate w-num+let.zip (632 Bytes)

[quote="MrC"]Here you go. It will add a number and letter to ensure uniqueness. You can adjust the max length. See the comment in side the script.

abcdefghijklmnopqrstuvwxzy 1.txt => abcdefghijklmnopqrstuv_1a.txt[/quote]

I noticed a problem with the script when the file name is already less than required, and have fixed that:

Truncate_numlet_2.zip (650 Bytes)

To use this (as with MrC's original), extract the zip file, to get the .orp (rename preset) file inside it. Then select some files and click Rename to open the Rename dialog. Then use the dialog's menus: File > Import, to load the preset.

Here's a screenshot which shows my change, commented out, and the original problem (which is still there because I commented out my change to make the screenshot).


I've deleted a bunch of off-topic (for this thread) posts.

General thing to keep in mind: If what you are about to post does not help the original poster answer their question, then you are making things harder for them & everyone trying to help them. Start a new thread instead, where those things can be discussed in their own space.

Thanks for the correction Leo.

In an upcoming 1.10 release of Dynamic Renamer, I've added this capability to the current trim (-x) option. It allows trimming N characters from the beginning or end of a file name, and the new change supports trimming to exactly N characters (leaving the head or tail N characters). It will look like:

-x trims 1 character from the front
-X trims 1 character from the end
-x4 trims 4 characters from the front
-X3 trims 3 characters from the end
-x=2 trims characters from the front, leaving the last two characters
-X=3 trims characters from the end, leaving the first 3 characters

Will it also allow trimming to -for instance- 150 characters, so much of the information about the name will remain in place?
Usually a long filename occurs when users put in detailed information about the contents. In case of many similarly named files
that info is mostly lost.

By "it" do you mean Leo's script or the -x option of Dynamic Renamer? For the latter, the trim is strictly based on character count.

How would you define what is the useful information? In other words, how would a computer program know what you think is useful and what you think is superfluous?

Very sorry MrC, it was Leo's script. Forget it.
As for character count: the computer doesn't need to know anything, but as said, long filenames usually
contains info what the file is about. If the file is truncated at (100, or 150) then many filenames are not
truncated and the filenames that are in fact truncated, they still show quite a lot of info about it's contents.

Else one may get filenames like
directory opus -file about#1.jpg
directory opus -file about#2.jpg

alternatively, of course, one cud use cutlongnames, but then again, this is a separate tool and a
Opus built-in feature would be much better :slight_smile:
http://s528.photobucket.com/user/phwul/slideshow/OpusPublic

=

It's not really my script, I just fixed a bug I noticed by adding two lines.

There's no reason an alternative script couldn't be written to truncate the names differently. You can use whatever rules you want.

The 26 character limit in that script seems to be related to how it makes the names unique (in case the truncated versions of two names are the same), but there are lots of other ways to solve that problem.

[quote="leo"]It's not really my script, I just fixed a bug I noticed by adding two lines.
[/quote]

You touch it, you own it. :slight_smile:

I am a bit embarrassed that I didn't remember writing the script in the first place. I'll chalk it up to getting older.

You seem to have written so many scripts I'm not surprised :slight_smile: