[Solved] WinRar script isn't working correctly (as a button)

Discuss and share scripts and script files...
Post Reply
highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

[Solved] WinRar script isn't working correctly (as a button)

Post by highend »

Hi,

I made a small script, that should invoke WinRAR on the current .zip/.rar file and extract it to a new directory in the current path. After that, it deletes the archive and selects the new directory.

If I select the archive and use Scripting - Try Script... everything works fine including the selection of the new dir but if I create a button that invokes the same script, the new directory isn't selected after the archive has been deleted.

Code: Select all

//Extract archive contents inside a folder, delete archive and select base folder
	$base = "<curbase>";
	run """C:\Program Files\WinRar\WinRAR.exe"" x ""<curitem>"" ""<curpath>\<curbase>\""",,1;
	delete 1, 0, <curitem>;
	sel "[$base]",,1;
Any hints why it isn't working correctly?

Regards,
highend
Last edited by highend on 07 Feb 2011 11:34, edited 1 time in total.
One of my scripts helped you out? Please donate via Paypal

atjnjk
Posts: 32
Joined: 04 Nov 2009 07:03

Re: WinRar script isn't working correctly (as a button)

Post by atjnjk »

Try this:

Code: Select all

   $base = "<curbase>";
   run """C:\Program Files\WinRar\WinRAR.exe"" x ""<curitem>"" ""<curpath>\<curbase>\""",,1;
   delete 1, 0, <curitem>;
   wait 100;
   sel "[$base]",,1;

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

Re: WinRar script isn't working correctly (as a button)

Post by highend »

The 100 ms pause helps sometimes, but not every time.

Is there a better way to check if

Code: Select all

delete 1, 0, <curitem>;
has finished successfully instead of increasing the wait time?
One of my scripts helped you out? Please donate via Paypal

atjnjk
Posts: 32
Joined: 04 Nov 2009 07:03

Re: WinRar script isn't working correctly (as a button)

Post by atjnjk »

This?

Code: Select all

   $base = "<curbase>";
   run """C:\Program Files\WinRar\WinRAR.exe"" x ""<curitem>"" ""<curpath>\<curbase>\""",,1;
   delete 1, 0, <curitem>;
   selfilter "[$base]", d,, 1;

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

Re: WinRar script isn't working correctly (as a button)

Post by highend »

Unfortunately, no.

Without a "wait xxx;" it has the same problem as the "sel" command.

Maybe a check if the archive still exists (after deleting it) and if the returncode
is 0 then perform the "sel" command.

But I haven't found anything how to evaluate return codes (via variables like
"errorlevel") in the help file ;)
One of my scripts helped you out? Please donate via Paypal

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: WinRar script isn't working correctly (as a button)

Post by nas8e9 »

Could it be a question of Background processing being enabled for deletes (Configuration > File Operations > Enable background processing, with it being applied to deletes)? If enabled, delete operations are handled asynchronously.

If so, by using the scripting command

Code: Select all

Setting('BackgroundFileOps', 0);
at the beginning of the script and setting it to 1 again at the end, deletes are handled before moving to the next script command.

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

Re: WinRar script isn't working correctly (as a button)

Post by highend »

@nas8e9

Thanks a lot, background processing is enabled in my config
and it's sufficient to place the command right in front of the delete command and at the end of the script.

Code: Select all

//Extract archive contents inside a folder, delete archive and select base folder
	$base = "<curbase>";
	$item = "<curitem>";
	run """C:\Program Files\WinRar\WinRAR.exe"" x ""<curitem>"" ""<curpath>\<curbase>\""",,1;
	Setting('BackgroundFileOps', 0);
	delete 1, 0, <curitem>;
	sel "[$base]",,1;
	Setting('BackgroundFileOps', 1);

I tried it 10 times without any issues. Works now :)
One of my scripts helped you out? Please donate via Paypal

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

Re: WinRar script isn't working correctly (as a button)

Post by admin »

FYI, your last line is not necessary:

Code: Select all

	Setting('BackgroundFileOps', 1);
Help wrote:Note that restoring options to their previous values, or user values, is not required: all modified options are restored automatically by XY when script execution ends (unless specified otherwise by using "p" as third parameter) regardless of how the script ended: normal termination, error, user cancellation...

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

Re: [Solved] WinRar script isn't working correctly (as a button)

Post by highend »

Ok, thank your for the clarification.

For future coding references:
Can you provide a small code example how to check the return value of a function?

Tia,
Highend
One of my scripts helped you out? Please donate via Paypal

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

Re: [Solved] WinRar script isn't working correctly (as a button)

Post by admin »

highend wrote:Ok, thank your for the clarification.

For future coding references:
Can you provide a small code example how to check the return value of a function?

Tia,
Highend
If your function is abc() then:

Code: Select all

$ret = abc(); echo "abc() returned " . $ret;

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

Re: [Solved] WinRar script isn't working correctly (as a button)

Post by highend »

Thanks a lot!
One of my scripts helped you out? Please donate via Paypal

Post Reply