Page 1 of 1
Instant Extension
Posted: 07 Jun 2012 05:59
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.
Re: Instant Extension
Posted: 07 Jun 2012 07:38
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
Re: Instant Extension
Posted: 07 Jun 2012 08:16
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.
Re: Instant Extension
Posted: 07 Jun 2012 08:27
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";
}
Re: Instant Extension
Posted: 07 Jun 2012 08:56
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...
Re: Instant Extension
Posted: 07 Jun 2012 09:10
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
Re: Instant Extension
Posted: 07 Jun 2012 10:19
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...
Re: Instant Extension
Posted: 07 Jun 2012 10:26
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";
}
Re: Instant Extension
Posted: 12 Jun 2012 08:03
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.