Please help I need a Script !

Discuss and share scripts and script files...
Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Please help I need a Script !

Post by Ysl »

Hi

I know almost anything in programming so I hope I will find some help !

I would like copy the name of an .mp3 file, delete it, and create a .txt file with the name of the mp3 file.

So pushing a key will transform "michael jackson - billie jean.mp3" to "michael jackson - billie jean.txt" (with a file size of 0 K)

Thanks for your help !

Ysl

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Please help I need a Script !

Post by TheQwerty »

Give this a try:

Code: Select all

End(GetInfo("CountSelected") < 1, "No item(s) selected.");
	Global($files);
	$files = Report("{Dir |{FullName};{Ext}<crlf>|}", 1);
	Setting("AllowRecursion", 1);
	Sub("_newTXT");
	RegexReplace($files, $files, "^(.*);.*<crlf>", "$1|");
	Delete(1,1,$files);


"_newTXT"
	Global($files, $i);
	$i = $i Like "" ? 1 : $i;
	$token = GetToken($files, $i, "<crlf>");
	End($token Like "",, 1);
	$file = GetToken($token, 1, ";");
	$ext = GetToken($token, 2, ";");
	RegexReplace($newFile, $file, "$ext$", "txt");
	New($newFile);
	$i = $i + 1;
	Sub("_newTXT");
Last edited by TheQwerty on 16 Apr 2009 22:52, edited 3 times in total.

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

THANKS ! so good so fast !

It works almost perfectly !

I have this error message :

Image

And I have to press continue for each file...

Thanks again !

Ysl

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Please help I need a Script !

Post by j_c_hallgren »

Ysl wrote:THANKS ! so good so fast !
Yes, TheQwerty is one of great scripters and very helpful as well!
I have this error message :
See our wiki for this one: http://88.191.26.34/XYwiki/index.php/IN ... hecker_Off
As it notes, one can do same via Setting.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

Perfect !

Thanks guys for your help and thanks XYplorer for scripting !

Ysl

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Please help I need a Script !

Post by TheQwerty »

Ysl wrote:It works almost perfectly !

I have this error message :
Doh.. Yep, I indeed forgot to disable the recursion checker in the script. Luckily, j_c_hallgren's always quick with finding the relevant parts of the wiki or forum posts.

In any case, I've updated the script above to temporarily disable the recursion checker.

Glad that works for you!

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

One last thing, I don"t know if it is possible but it would save time

Can we pass the delete confirmation panel and delete without asking ?

Thanks

Ysl

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Please help I need a Script !

Post by TheQwerty »

Ysl wrote:Can we pass the delete confirmation panel and delete without asking ?
Take a look here: http://88.191.26.34/XYwiki/index.php/Sc ... nd:_delete
Then you can change the Delete command to work however you'd like.
You'll probably want "Delete(1,0,$files);"

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

It's even better now !

Merci encore !

Ysl

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

May I ask one more refinement ?

I would like to select all the files in a folder (.jpg, mp3, txt) and when I run the script, I would like for only the mp3 to be renamed/deleted.

There should be a "if -then" command somewhere which can do that I hope...

Thanks

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Please help I need a Script !

Post by TheQwerty »

Ysl wrote:I would like to select all the files in a folder (.jpg, mp3, txt) and when I run the script, I would like for only the mp3 to be renamed/deleted.
It would probably be smarter to use a selection or visual filter, but I've updated the above code and it should ignore anything that doesn't have the extension mp3.
Ysl wrote:There should be a "if -then" command somewhere which can do that I hope...
Unfortunately, XY scripting does not yet have real if-else constructs, so it's not that easy. As I wanted to keep the Delete as a single bulk call it won't be that easy even when he gives them to us.

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

Well, Thanks again for your help but unfortunately, the script work as before, the "folder.jpg" was renamed "folder.txt" and deleted...

Ysl

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Please help I need a Script !

Post by TheQwerty »

Yeah.. that's not going to work.

Can't you just use a Selection or Visual filter so you're only dealing with MP3s in the first place?

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

I don't really understand those options but will look in the manual !

Ysl
Posts: 153
Joined: 03 Jan 2007 22:22

Re: Please help I need a Script !

Post by Ysl »

Hi

It seem that since 8.50 or 8.60, this script doesn't work anymore !

When running it, all that happen is a new file in the same folder

Name of the new file (which should be the same as the selected one but with the .txt extension) : $newFile

Thanks for your help !

Ysl

Post Reply