Instant Extension

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Instant Extension

Post by aimy »

Hi all.

It's pretty basic and straight forward.

How do I made a script to instantly change the file extension?

The idea is sometimes I want to hide certain songs folder from my car fm modulator. I've tried several hide folder software but it just didnt work.

So I thought the only solution is to rename the *.mp3 extension of those files.

I've tried the manual way but it's quite slow to rename all those 500 songs :(

Is there anyway for a quick one so that I can assign it to a single button processing?

Thank you.

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

Re: Instant Extension

Post by highend »

Code: Select all

// Rename file extension from mp3 to zzz and vice versa

	$item = gettoken(<get SelectedItemsNames |>, 1, "|");

	if(strpos($item, ".mp3") != -1) {
		rename e, "zzz";
	} else {
		rename e, "mp3";
	}

But try it with your files in a temp dir first. It seems rename e,... has issues with additional dots in the filename. Have to check that
Last edited by highend on 07 Jun 2012 10:28, edited 1 time in total.
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: Instant Extension

Post by aimy »

highend wrote:

Code: Select all

// Cut long names

	foreach($Item, <get SelectedItemsNames |>) {
		rename e, "", p;
	}
But try it with your files in a temp dir first. It seems rename e,... has issues with additional dots in the filename. Have to check that
Thanks a lot.

Seems to work fine without the preview and cater my objective.

But, could I make it a toggle button? Means the extension will change automatically everytime i click on it?

i.e. 1st time click, --> *.mpz, 2nd time click --> *.mp3 and it goes around.

can i?

Thanks.

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

Re: Instant Extension

Post by highend »

Sure.

Code: Select all

// Rename file extension from mp3 to zzz and vice versa

	$item = gettoken(<get SelectedItemsNames |>, 1, "|");

	if(strpos($item, ".mp3") != -1) {
		rename e, "zzz";
	} else {
		rename e, "mp3";
	}

Last edited by highend on 07 Jun 2012 10:28, edited 1 time in total.
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: Instant Extension

Post by aimy »

highend wrote:Sure.

Code: Select all

// Cut long names

	foreach($Item, <get SelectedItemsNames |>) {
		if(strpos($Item, ".mp3") != -1) {
			rename e, "";
		} else {
			rename e, "mp3";
		}
	}
wow.. thanks a lot :)

last one... can I assign a shortcut key to this button? huhu...

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

Re: Instant Extension

Post by highend »

Mh, I don't think so but I may be wrong.

As an alternative, keyboard shortcuts can be assigned to scripts via
Menu - User - Manage Commands...

Left side: Run Script
One of my scripts helped you out? Please donate via Paypal

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Instant Extension

Post by PeterH »

Oh - this belongs to the "bug"-thread?

As said there: the "rename", called once, renames all seleced items. And here it is called multiple, in a loop.

Or seen in another way: you call rename in a loop, but don't supply it with loop-information, that is with $item. So it can't do what the loop is thought for...

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

Re: Instant Extension

Post by highend »

Don't use one of the last scripts. It's not a good idea to actually replace the extension with nothing.
If a file name contains a dot everything after that dot will be renamed to "mp3" if you click
the button a second time.

Select all files manually (BE SURE TO REALLY SELECT ONLY .mp3 FILES) and use this one:

Code: Select all

// Rename file extension from mp3 to zzz and vice versa

	$item = gettoken(<get SelectedItemsNames |>, 1, "|");

	if(strpos($item, ".mp3") != -1) {
		rename e, "zzz";
	} else {
		rename e, "mp3";
	}
One of my scripts helped you out? Please donate via Paypal

aimy
Posts: 186
Joined: 26 Feb 2007 15:44

Re: Instant Extension

Post by aimy »

highend wrote:Don't use one of the last scripts. It's not a good idea to actually replace the extension with nothing.
If a file name contains a dot everything after that dot will be renamed to "mp3" if you click
the button a second time.

Select all files manually (BE SURE TO REALLY SELECT ONLY .mp3 FILES) and use this one:

Code: Select all

// Rename file extension from mp3 to zzz and vice versa

	$item = gettoken(<get SelectedItemsNames |>, 1, "|");

	if(strpos($item, ".mp3") != -1) {
		rename e, "zzz";
	} else {
		rename e, "mp3";
	}
Thanks a lot. Really helps.

Post Reply