Page 1 of 3

Extracting a zip file to its own folder

Posted: 24 Dec 2013 08:18
by Neddy
Hi all. I'm a new XY user trying to meld XY into my subconscious like I have with Windows Explorer.

Something I do a lot is extract compressed archive files (mostly zips) to their own folder.
Like extract the contents of "my.zip" to a new folder named "my".
There's an option to do this very thing right in XYPlorer: right-click, then "Zip" then "Extract to <my>\"

But there doesn't seem to be a keyboard shortcut for that. I tried to make a new kbd shortcut but couldn't find this action. Where's it at?

(I also found an add on script called Extractor posted herebut I'm hoping to learn how find these actions.

Re: Extracting a zip file to its own folder

Posted: 24 Dec 2013 09:35
by highend
There isn't any "zip to" action that can be bound to a keyboard shortcut. Not every single context menu command is available as such but it can be scripted...

Re: Extracting a zip file to its own folder

Posted: 24 Dec 2013 12:17
by 40k
Best way to go about this is write a script.

Re: Extracting a zip file to its own folder

Posted: 25 Dec 2013 13:07
by highend
Advantage: Works for all selected files, not only a single one...

Code: Select all

    foreach($item, get("SelectedItemsPathNames", "|"), "|") {
        if ($item != "" && getpathcomponent($item, "ext") == "zip") {
            zip_extract($item, getpathcomponent($item, "base"), , "|");
        }
    }
    status "Extraction of archive(s) completed...", "00800000", "ready";

Re: Extracting a zip file to its own folder

Posted: 25 Dec 2013 21:19
by Neddy
Highend, that sounds perfect.
Can someone help me understand the script a bit?

Code: Select all

    foreach($item, get("SelectedItemsPathNames", "|"), "|") {
So we'll be looping through each selected file and in each iteration of the loop $item will refer to a different selected file.

Code: Select all

        if ($item != "" && getpathcomponent($item, "ext") == "zip") { 
If the file's extension is "zip", stuff happens, otherwise it's skipped.
Is this case insensitive?

Code: Select all

            zip_extract($item, getpathcomponent($item, "base"), , "|"); 
This is the interesting one.

Looks like the call for the zip_extract function is:
zip_extract(zipfile, path, [itemlist], [separator="|"])

Why the pipe as the 4th param? Is it possible getpathcomponent($item, "base") could return multiple files? What could cause that? And why would they be pipe separated?

Thanks so much for the replies everyone :-)

Re: Extracting a zip file to its own folder

Posted: 25 Dec 2013 22:24
by highend
Is this case insensitive?
Yes
Why the pipe as the 4th param?
To separate items in the itemlist.
Is it possible getpathcomponent($item, "base") could return multiple files?
No, but why should it? There is a while | foreach loop to do such things.
What could cause that? And why would they be pipe separated?
Never thought of it...

Re: Extracting a zip file to its own folder

Posted: 27 Dec 2013 10:46
by nerdweed
The pipe character isn't accepted as a valid file name and hence it becomes a good choice as a delimeter.

Re: Extracting a zip file to its own folder

Posted: 03 Aug 2014 20:00
by CookieMonster
Is it possible to extract a single file from a zip file ? I love XY has built in compressor, as I migrate XY to be my one stop program for file managing and much more.

Re: Extracting a zip file to its own folder

Posted: 03 Aug 2014 21:09
by highend
rtfm "idh_scripting_comref.htm#idh_sc_zip_extract";

Re: Extracting a zip file to its own folder

Posted: 04 Aug 2014 00:59
by CookieMonster
highend wrote:rtfm "idh_scripting_comref.htm#idh_sc_zip_extract";
FYI, I read the manual, not the scripting portion. I loaded the command in the address bar, nothing happens :?:

Re: Extracting a zip file to its own folder

Posted: 04 Aug 2014 03:01
by RalphM
I added two colons at the start, now paste this into the AB and hit enter.

Code: Select all

::rtfm "idh_scripting_comref.htm#idh_sc_zip_extract";

Re: Extracting a zip file to its own folder

Posted: 04 Aug 2014 03:33
by CookieMonster
RalphM wrote:I added two colons at the start, now paste this into the AB and hit enter.

Code: Select all

::rtfm "idh_scripting_comref.htm#idh_sc_zip_extract";
Too many languages and keyboard short-cuts for programs I use; XY is always last to remember :)

Re: Extracting a zip file to its own folder

Posted: 04 Aug 2014 07:11
by CookieMonster

Code: Select all

text zip_extract("<network drive>\<folder>\<zipfile>","<folder>","<specific file I only want extracted>");
I get a popup that gives me the folder in which I wanted to extract the specific file too but no file is extracted ?

Re: Extracting a zip file to its own folder

Posted: 04 Aug 2014 07:27
by autocart
Sorry, but the way you posted it, it can't work. (These <...> that you used are just not recognized by XY. I dunno how you came up with that.)
The last example in the help file should be exactly what you want, I think, and it works, at least on my machine.

Re: Extracting a zip file to its own folder

Posted: 04 Aug 2014 07:55
by SammaySarkar
@CookieMonster: Do you have write access to the target path? (I ask because apparently it's a net path)
Try extracting to a local path.

@autocart: I'm pretty sure CM used those <terms> as placeholders in the post only, and not in the script. :)