Page 1 of 1
[Solved] WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 02:40
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
Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 03:19
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;
Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 03:28
by highend
The 100 ms pause helps sometimes, but not every time.
Is there a better way to check if
has finished successfully instead of increasing the wait time?
Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 06:27
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;
Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 10:26
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

Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 10:54
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
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.
Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 11:31
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

Re: WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 12:57
by admin
FYI, your last line is not necessary:
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...
Re: [Solved] WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 13:50
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
Re: [Solved] WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 15:08
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;
Re: [Solved] WinRar script isn't working correctly (as a button)
Posted: 07 Feb 2011 15:37
by highend
Thanks a lot!