Is it possible(with some script maybe)to cut long file names.
For example,selecting multiple files with names that have more than 100 characters,to cut the last characters that exceed the limit(the limit will be for example 100 characters)...keep the first 100 and cut the rest of the name.
Rename\Cut long names?
Re: Rename\Cut long names?
Yes you can do that.
But make that sense?
Maybe better shorten the string with some tricks like 1-4a Renamer does?
Like
* delete unnecessary spaces after brackets
* abbreviate parts of the file name
* NoSpaceBetweenLetters
* No doubles: Madonna > Madona
* Kill Vowels
Anyway, if you want you can try this test script on an handful testfiles first :
* get SelectedItemsNames will get all selected file names
* foreach(){} will loop over all files in the array
* substr() will take an part of the string
* rename will rename (while keeping the original extension in this shown setup)
and preview you each file before actual renaming ("p").
* since we have gotten the file names without the path,
we have to use smtg like "<curpath>\$Item"; for the rename command
(While the newname-part works on the current folder, the currentName-part does not and can not find $Item alone. Don?)
Read the help "Scripting Commands Reference" for more.
Hint: if you Cancel the rename preview, you will see the XYplorer scripting window (click)
EDIT: good idea with checking if the new string is shorter then the original, highend! Changed mine too.
But make that sense?
Maybe better shorten the string with some tricks like 1-4a Renamer does?
Like
* delete unnecessary spaces after brackets
* abbreviate parts of the file name
* NoSpaceBetweenLetters
* No doubles: Madonna > Madona
* Kill Vowels
Anyway, if you want you can try this test script on an handful testfiles first :
Code: Select all
foreach($Item, <get SelectedItemsNames |>) {
msg $Item,1;
$NewFilename = substr($Item,0,96);
if( strlen($NewFilename) < strlen($Item)){
msg "$NewFilename + Original ext",1;
rename b, "$NewFilename", p, "<curpath>\$Item";
}else{
msg "Nothing to do.";
}
}
* foreach(){} will loop over all files in the array
* substr() will take an part of the string
* rename will rename (while keeping the original extension in this shown setup)
and preview you each file before actual renaming ("p").
* since we have gotten the file names without the path,
we have to use smtg like "<curpath>\$Item"; for the rename command
(While the newname-part works on the current folder, the currentName-part does not and can not find $Item alone. Don?)
Read the help "Scripting Commands Reference" for more.
Hint: if you Cancel the rename preview, you will see the XYplorer scripting window (click)
EDIT: good idea with checking if the new string is shorter then the original, highend! Changed mine too.
Last edited by Stefan on 06 Jun 2012 09:35, edited 2 times in total.
Re: Rename\Cut long names?
Code: Select all
// Cut long names
$cLimit = 100;
$sItems = get("SelectedItemsNames", "|");
foreach($item, $sItems, "|") {
if(strlen($item) > $cLimit){
$ext = gettoken($item, -1, ".");
$cExt = strlen($ext);
$nName = substr($item, 0, $cLimit -$cExt -1) . "." . $ext;
renameitem($nName, $item, 3);
}
}
Apart from that you can adjust the length at the beginning of the script.
One of my scripts helped you out? Please donate via Paypal
Re: Rename\Cut long names?
I don't really care about the full name(only few characters at the beggining)...the whole point of the renaming is to not see the tooltip on files with long file names(in any view mode in Explorer if you can't see the whole name of the file,when you hover over it,it will show a tooltip with the full name which is annoying because it's hiding the other files).
I'm also using shell extension that shows preview on images and that long name tooltip is always over the preview tooltip.
If someone know a way to disable the name tooltip on files,that will be better than renaming but till now I haven't find a way to do that(only to disable everything else except the name)
I already find a program(ReNamer)and rename all of the files but thanks anyway.
I'm also using shell extension that shows preview on images and that long name tooltip is always over the preview tooltip.
If someone know a way to disable the name tooltip on files,that will be better than renaming but till now I haven't find a way to do that(only to disable everything else except the name)
I already find a program(ReNamer)and rename all of the files but thanks anyway.
-
- Site Admin
- Posts: 60632
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Rename\Cut long names?
Untick Configuration | File Info Tips | Show tips for clipped tree and list items.
FAQ | XY News RSS | XY Twitter
Re: Rename\Cut long names?
highend wrote: ↑06 Jun 2012 09:26Code: Select all
// Cut long names $cLimit = 100; $sItems = get("SelectedItemsNames", "|"); foreach($item, $sItems, "|") { if(strlen($item) > $cLimit){ $ext = gettoken($item, -1, "."); $cExt = strlen($ext); $nName = substr($item, 0, $cLimit -$cExt -1) . "." . $ext; renameitem($nName, $item, 3); } }
hello sir,
if any file name exists with same file name , this code is not progressing further. can you please add sequence numbers to the same file names without asking the user for confirmation?
Re: Rename\Cut long names?
Look up renameitem() and add the
[numsuffix]
part?One of my scripts helped you out? Please donate via Paypal
Re: Rename\Cut long names?
thanks a lot. it is working now.