openwith only <item>

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: openwith only <item>

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: openwith only <item>

Post 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.

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: openwith only <item>

Post 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 :roll:

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

Re: openwith only <item>

Post 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*/;
  }

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: openwith only <item>

Post 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 .

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

Re: openwith only <item>

Post by TheQwerty »

I'm confused by your last post... That last script works fine here - what isn't working for you?

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: openwith only <item>

Post by nerdweed »

Indeed it does when I copied it entirely. I didn't integrate it properly then. Thanks . :appl: :appl:

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

Re: openwith only <item>

Post 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>"

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: openwith only <item>

Post 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.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: openwith only <item>

Post 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.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: openwith only <item>

Post by nerdweed »

Finally, it worked the first command. Thanks for your help TheQwerty and Sammay

Post Reply