Page 2 of 2
Re: openwith only <item>
Posted: 10 Jul 2014 14:16
by bdeshi
Are you really sure WinRAR can extract multiple archives at once via cmdline?
This is from winrar manual, the commanline syntax:
WinRAR <command> -<switch1> -<switchN> <archive> <files...> <@listfiles...> <path_to_extract\>
<archive> : The name of the archives to process.
Just to be sure, I tried your given cmd in an actual command prompt:
"C:\Program Files\WinRAR\WinRAR.exe" x -- "C:\arc\file1.zip" "C:\arc\file2.zip" "C:\arc\" with both one and multiple archives.
and it gave the same errors as described. So, XY is of the hook, to me at least.
Re: openwith only <item>
Posted: 10 Jul 2014 14:31
by TheQwerty
This is what I am using within my script for this:
Code: Select all
OpenWith """C:\Program Files\winrar\winrar.exe"" X -- <items> ""<curpath>""", 'm';
It uses a separate instance for each file but I know it works.
Re: openwith only <item>
Posted: 10 Jul 2014 14:47
by nerdweed
Yes, even I am using the m for multiple instance. The command posted by TheQwerty works great. However, when I pass a user variable even in the same format it doesn't work. No matter if the variable contains single or multiple file paths.
The reason for using another variable is to filter out non-archive files before passing it onto WinRAR and avoiding obvious error dialogs.
Rereading Sammay's post it seems that XY is able to do something that normal cmd cannot.
Question: What does <items> do differently that a variable with identical contents doesn't

Re: openwith only <item>
Posted: 10 Jul 2014 15:13
by TheQwerty
nerdweed wrote:However, when I pass a user variable even in the same format it doesn't work. No matter if the variable contains single or multiple file paths.
That's technically correct - OpenWith doesn't open the specified files it "opens the currently selected List item(s)" - so it is working as designed.
You'd want to use a foreach loop to enumerate your variable and call run for each item.
Code: Select all
$items = Get('SelectedItemsPathNames', '|');
// Extensions to accept.
$archiveExts = '*.zip|*.rar|*.7z';
// Filter the list to only the acceptable archives.
$items = FormatList($items, 'f', '|', $archiveExts);
End $items == '', 'No archives selected.';
foreach ($item, $items, '|') {
// Build our command using a HEREDOC to make it legible.
$cmd = <<<CMD
"C:\Program Files\winrar\winrar.exe" X -ad -- "$item" "<curpath>"
CMD;
// Run the command in the current path, don't wait for it to complete, and minimize its window.
Run $cmd, "<curpath>", 0 /*continue*/, 2 /*minimize*/;
}
Re: openwith only <item>
Posted: 10 Jul 2014 21:10
by nerdweed
Thanks TheQwerty
Sadly, as Sammay said passing it directly through Command line doesn't work either. I trust my next best bet would be to the filter the items, issue the command and then restore selection.
I had given it a quick try yesterday, but would need to consider it seriously.
Even though openwith was not designed to work this way, it's still surprising how the same command doesn't work .
Re: openwith only <item>
Posted: 10 Jul 2014 21:14
by TheQwerty
I'm confused by your last post... That last script works fine here - what isn't working for you?
Re: openwith only <item>
Posted: 10 Jul 2014 22:01
by nerdweed
Indeed it does when I copied it entirely. I didn't integrate it properly then. Thanks .

Re: openwith only <item>
Posted: 10 Jul 2014 22:25
by TheQwerty
Actually... that might not do exactly what you had wanted. I just noticed I accidentally left in the
-ad switch which tells it to append the archive name to the destination path.
If you'd rather it actually extract them all directly to the current path just replace:
Code: Select all
"C:\Program Files\winrar\winrar.exe" X -ad -- "$item" "<curpath>"
with
Code: Select all
"C:\Program Files\winrar\winrar.exe" X -- "$item" "<curpath>"
Re: openwith only <item>
Posted: 10 Jul 2014 23:34
by nerdweed
That's completely fine. I have been using them both.
I am writing the whole script within a Heredoc block and this is giving me a hard time
Code: Select all
// Build our command using a HEREDOC to make it legible.
$cmd = <<<CMD
"C:\Program Files\winrar\winrar.exe" X -ad -- "$item" "<curpath>"
CMD;
As Heredoc cannot be nested, I tried various permutations but got stuck again.
I have tried the below options
Run """$WinRAR"" X -ad ""$item"" ""<curpath>""", "<curpath>", 0 /*continue*/, 2 /*minimize*/;
Run ""$WinRAR"" X -ad ""$item"" ""<curpath>"", "<curpath>", 0 /*continue*/, 2 /*minimize*/;
$cmd='"C:\Program Files\winrar\winrar.exe" X -ad -- "$item" "<curpath>"' ;
Run $cmd, "<curpath>", 0 /*continue*/, 2 /*minimize*/;
$cmd="""C:\Program Files\winrar\winrar.exe"" X -ad -- ""$item"" ""<curpath>""' ;
Run $cmd, "<curpath>", 0 /*continue*/, 2 /*minimize*/;
It is failing at resolving $item. It says the file is corrupt. Can you tell me where I am erring.
Re: openwith only <item>
Posted: 11 Jul 2014 08:22
by bdeshi
nerdweed wrote:I have tried the below options ...
Assuming the file is not really corrupt, the first code works fine. But the second and third commands are not quoted correctly. The fourth cmd will work if the last single-quote in $cmd is replaced with a double-quote. (that's probably a typo)
======
Concerning <items> and openwith, I think openwith sends each item in <items> to the target app one by one. So if you have selected three files, then openwith runs the command three times:
(pseudocode)
app.exe -args file1
app.exe -args file2
app.exe -args file3
If the
s pararmeter is given then maybe XY uses hWnd to try sending each command to the same instance of the target app.
Re: openwith only <item>
Posted: 11 Jul 2014 23:11
by nerdweed
Finally, it worked the first command. Thanks for your help TheQwerty and Sammay