Rename\Cut long names?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
vsub
Posts: 69
Joined: 23 Nov 2010 19:07

Rename\Cut long names?

Post by vsub »

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.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Rename\Cut long names?

Post by Stefan »

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 :

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.";
      }
   }
* 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.
Last edited by Stefan on 06 Jun 2012 09:35, edited 2 times in total.

highend
Posts: 13338
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename\Cut long names?

Post by highend »

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);
		}
	}
It doesn't take care if the last position before the extension contains a space.

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

vsub
Posts: 69
Joined: 23 Nov 2010 19:07

Re: Rename\Cut long names?

Post by vsub »

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.

admin
Site Admin
Posts: 60632
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Rename\Cut long names?

Post by admin »

Untick Configuration | File Info Tips | Show tips for clipped tree and list items.

lian00
Posts: 368
Joined: 09 Jul 2014 17:12

Re: Rename\Cut long names?

Post by lian00 »

Thanks for the code. :appl:
Windows 10 64 bits

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: Rename\Cut long names?

Post by kotlmg »

highend wrote: 06 Jun 2012 09:26

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);
		}
	}

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?

highend
Posts: 13338
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename\Cut long names?

Post by highend »

Look up renameitem() and add the [numsuffix] part?
One of my scripts helped you out? Please donate via Paypal

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: Rename\Cut long names?

Post by kotlmg »

thanks a lot. it is working now.

Post Reply