Page 1 of 2

openwith only <item>

Posted: 08 Jul 2014 00:15
by nerdweed
A quick question. How does the openwith only variable <item> pass the selected item lists

This works fine
openwith ("""$WinRAR"" x -- <items> ""<curpath>""", m) ;

Whereas this doesn't
openwith ("""$WinRAR"" x -- $Files ""<curpath>""", m) ;
I have tried with $Files as (mentioned with the required quoting). The filenames are full paths and can contain spaces
1. ""File1" "File2" ... "Filen""
2. "File1 File2 .. Filen" //Though knew this wouldn't work

Why?
$Files is a subset of the selected items

Re: openwith only <item>

Posted: 08 Jul 2014 00:28
by highend
put a step; before your command and see how the $files resolves?

Re: openwith only <item>

Posted: 08 Jul 2014 10:51
by nerdweed
I did and it resolves either as mentioned in 1 and 2 (I meant them to be the resolved ones rather than the written ones).
1. """""" . """File1""" . """File2""" ... . """Filen""" . """"""
resolves to
""File1" "File2" ... "Filen""

2. $Files = """" . "File1 File2 ... File n" . """"
resolves to
"File1 File2 .. Filen"
The step dialog doesn't show the resolved <items> so not sure where I am going wrong.

I forgot to mention that, using that command with $Files opens up the base folder in Windows Explorer rather than extracting the files.

With <items> the files are properly extracted.

P.S. Not in front of my code, so might have slightly mistyped.

Re: openwith only <item>

Posted: 08 Jul 2014 11:49
by highend
1. If your $files resolves to something like:
"D:\a.txt D:\b.txt"
instead of
"D:\a.txt" "D:\b.txt"

it won't work (with Winrar).
So you're doing something wrong when you build that $files variable.

But... you don't post your code so how should we know what you're doing there...

Apart from that you should put $files in double quotes.

Code: Select all

openwith ("""$WinRAR"" x -- ""$Files"" ""<curpath>""", m) ;
Apart from that, openwith is no function with a return value.

Code: Select all

openwith """$WinRAR"" x -- ""$Files"" ""<curpath>""", m ;
And at last...

To see how <items> are resolved (they are quoted for each item separately like:
"D:\a.txt" "D:\b.txt" etc.

use a batch file with:

Code: Select all

echo %*
pause
and call it like:

Code: Select all

openwith """<full path to the batch file.bat>"" x -- <items> ""<curpath>""", m ;

Re: openwith only <item>

Posted: 08 Jul 2014 19:35
by nerdweed

Code: Select all

"Extract"
 $ext = ".*\.zip|.*\.rar|.*\.7z$" ;
 $Files = """""" . Replace(RegExMatches(Get("SelectedItemsPathNames"), $ext, "<crlf>"),"<crlf>", """ """) . """""" ; 
 If ($Files != "") {
  openwith ("""$WinRAR"" x -- $Files ""<curpath>""", m) ;
 }
I will try the batch file to see what I am doing wrong. Thanks.

Edit: I doubled the quotes inside the quotes, had to do it twice as the quotes are present again.
$Files = """""" . Replace(RegExMatches(Get("SelectedItemsPathNames"), $ext, "<crlf>"),"<crlf>", """"" """"") . """""" ;
It triggers WinRAR but it doesn't extract anything though

Re: openwith only <item>

Posted: 08 Jul 2014 20:46
by PeterH
You know that in XY """""" is the same as '""' ?

Double quotes in double quotes must be doubled, double quotes in single quotes not.
Variables in single quotes are taken as literal - but there are none :D

Same for """ """ :arrow: you may use '" "'

So compare:

Code: Select all

 $Files = """""" . Replace(RegExMatches(Get("SelectedItemsPathNames"), $ext, "<crlf>"),"<crlf>", """ """) . """""" ;
 $Files = '""' . Replace(RegExMatches(Get("SelectedItemsPathNames"), $ext, "<crlf>"),"<crlf>", '" "') . '""' ;
And I'm not sure: do syntax rules request that <crlf> must be quoted?

Re: openwith only <item>

Posted: 08 Jul 2014 21:16
by nerdweed
Thanks for reminding about single quotes. Did that now.
Quoting <crlf>, I often do it since Don once said quoting would ensure compatibility (though not explicitly for this).

Lets, leave the remaining code and parsing of $Files aside for now.
openwith """$WinRAR"" x -- ""D:\ToggleCdolumns.zip"" ""<curpath>""", m ;
Even this doesn't work. Though it invokes WinRAR, the below message is displayed
! D:\ToggleCdolumns.zip: No files to extract
This isn't true because the same file extracts just fine when <items> is used. :bug:

Re: openwith only <item>

Posted: 09 Jul 2014 13:00
by nerdweed
Can anyone repro this. It doesn't work with WinRAR, it says file is corrupt.

BandiZip extracts all files multiple times - once for each file passed.

<items> works ok.

Re: openwith only <item>

Posted: 09 Jul 2014 13:34
by bdeshi
Does WinRAR allow eXtracting multiple files at once, like winrar x "archive1.rar" "archive2.zip" "extraction\path\"?

Re: openwith only <item>

Posted: 09 Jul 2014 14:57
by nerdweed
Yes, it does. <items> extracts its just fine.

And it fails even on passing a single file - it does open WinRAR but reports the file is corrupt. Like Highend suggested, I checked the parameters using a bat file and they match. Don't know whats causing this.

To Summarize,
1. The below reports corrupt file in WinRAR
openwith """$WinRAR"" x -- ""D:\ToggleCdolumns.zip"" ""<curpath>""", m ;

2. This works fine when, <items> is D:\ToggleCdolumns.zip
openwith """$WinRAR"" x -- <items> ""<curpath>""", m ;

Tried it with BandiZip, as well for two items D:\File1.zip and D:\File2.zip
3. It extracts with BandiZip but both files are extracted twice. Workd well with only on archive
openwith """$BandiZip"/extract_autodest ""<curpath>"" ""D:\File1.zip"" ""D:\File2.zip"""

4. Withe <items> it works fine and extracts only once
openwith """$BandiZip"/extract_autodest ""<curpath>"" <items>"

Re: openwith only <item>

Posted: 09 Jul 2014 15:10
by bdeshi
I just fetched WinRAR. I can confirm what you've reported.
nerdweed wrote:3. It extracts with BandiZip but both files are extracted twice. Workd well with only on archive
openwith """$BandiZip"/extract_autodest ""<curpath>"" ""D:\File1.zip"" ""D:\File2.zip"""
Does this still extract twice if you stick a ,s,; at the end?

Re: openwith only <item>

Posted: 09 Jul 2014 16:23
by nerdweed
I didn't explicitly mention s as I believe that is the default mode. Will check it in a few hours by explicitly mentioning s for bandizip.

Re: openwith only <item>

Posted: 09 Jul 2014 18:22
by bdeshi
There's also a "," after the "s", which is supposed to give custom filelist (in this case it's rendered empty).
My logic is that because multiple files are selected, XY is running the command twice, for both files. Since the command already apparently includes all files, let's give it an empty filelist.
Can't confirm tho'.

Re: openwith only <item>

Posted: 09 Jul 2014 22:37
by nerdweed
It gives a No archives found error if I pass it as the last parameter or no files.

No joy with ,s, / ,m, /,, either.

Regardless of Bandizip being called multiple times, WinRar is called only once unless I pass ,m, parameter.

Re: openwith only <item>

Posted: 10 Jul 2014 11:57
by nerdweed
Don, would you be able to help with this.