Page 1 of 2

Extracting a Zip file to a folder via CTB

Posted: 02 Jul 2014 20:39
by aurumdigitus
Have been very pleased since Zips were incorporated natively into XY.

An operation that occurs with great frequency here is to extract a Zip file's contents to a folder with that name. Now Command #280 "Extract here" is provided. However, that just dumps the files into the same folder.

Can a script be written that can be placed into a CTB that will take the selected Zip, create a folder with the same name and then put the extracted files in there?

Re: Extracting a Zip file to a folder via CTB

Posted: 02 Jul 2014 20:47
by Stef123
aurumdigitus wrote:Have been very pleased since Zips were incorporated natively into XY.
Am I missing something? Doesn't work here. Neither on portable nor on install? :veryconfused:

Re: Extracting a Zip file to a folder via CTB

Posted: 02 Jul 2014 21:04
by aurumdigitus
Maybe wrong nomenclature?

Try this: Right click a file with Zip extension, slide down for lines to zip, the menu opens.

Re: Extracting a Zip file to a folder via CTB

Posted: 02 Jul 2014 21:08
by klownboy
You may want to give highend's very nice "Extractor" a try. It will unzip the current file into a new folder with the name of the zip file. It's a button on my toolbar. http://www.xyplorer.com/xyfc/viewtopic. ... lit=autoit
There's an option to delete the file after extraction or keep it as well. It uses AHK but he has provided a compiled version and it will utilize the extractor of your choice.

Re: Extracting a Zip file to a folder via CTB

Posted: 02 Jul 2014 21:25
by Stef123
aurumdigitus wrote:Right click a file with Zip extension, slide down for lines to zip, the menu opens.
Throws an error - which does not surprise me since I am on XP right now, but even my Win7 systems override the (really bad) Win zippers with tools that XY does not recognize.

I guess we have a very different interpretation of what you call "incorporated natively into XY" :cry:
klownboy wrote:You may want to give highend's very nice "Extractor" a try.
I did. Definitely an improvement. But still a far cry from the native support in other managers (my main reason for still using them).

Re: Extracting a Zip file to a folder via CTB

Posted: 02 Jul 2014 21:52
by aurumdigitus
I guess we have a very different interpretation of what you call "incorporated natively into XY" :cry:
Must be that Zipping like beauty is in the eye of the beholder. Thus far - except for the query that initiated the thread - XY has been able to handle all my compression/decompression needs.

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 05:28
by Stef123
aurumdigitus wrote:XY has been able to handle all my compression/decompression needs.
Again - it's 3rd party that handles it. I didn't mean to question your taste :wink: , you made me question my workflow - if maybe I had overlooked something. :?:

Zipping is a function in my eyes. You'll drop your "beauty" the very instant XY tempts you with native support in list view. Bet on it. It's all about efficiency and comfort - not about loyalty to an old way of doing things.

Until then, I think highend's script will do exactly what you asked for.

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 14:28
by aurumdigitus
Again - it's 3rd party that handles it. I didn't mean to question your taste :wink:
Coding and scripting are largely outside my sphere of cognition. What XY is doing with Zips appears to be transparent - however Don pulls it off.

Anyway, as no one has come forward with a custom XYS will examine highend's Extractor as has been suggested.

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 14:42
by mkolaski
No idea where I found this, but I've got the following set up for handling zip files:

Code: Select all

"_Initialize";
   perm $p_zip = "C:\Program Files\7-Zip\7zG.exe";
   perm $p_Zip = "C:\Program Files\7-Zip\7zFM.exe";
"just a message on winmount" msg "will NOT work on Winmount scripted created 7z files. <br> 7z created in the GUI will work. "
"&Open <curname> : open"
    openwith "$p_Zip";
-
"&List all this folder "
      selfilter "*.rar ; *.7z ; *.cab ; *.gz ; *.zip";
       $SelectedItems = get("SelectedItemsNames", "|");
   foreach($Item, $SelectedItems, "|") {
       rename s, " /";
        }
      wait 500;
      selfilter "*.rar ; *.7z ; *.cab ; *.gz ; *.zip";
       $SelectedItems = get("SelectedItemsNames", "|");
        foreach($Item, $SelectedItems, "|") {
         Run("cmd /c $p_zip l $Item >> <curfolder>.txt");
         wait 500;
          }
"List  <curname> single"
         rename s, " /";
        Run("cmd /c $p_zip l <curitem> > <curitem>.txt");
-
"7-Zip and move. (<curbase>.&7z and move) : 7z"
    focus;
    #113;
    focus;
    $curbase= <clipboard>;
    $l = strlen ($curbase);
    $p = strpos ($curbase, <crlf>);
   $curbase = regexreplace ($curbase, "^-1$", "$l");
    if ($p = "-1") { $p = $l ; }
    $curbase = substr ($curbase, 0, $p);
    $curbase = replace ($curbase," ","_");
   set $curbase, "$curbase.7z";
//Compress file with .zip. Name= base of file.
   $a =  get("path", i);
   openwith """$p_zip"" a -t7z $a\$curbase";
-
"Convert into <curbase>.&zip : zip"
  focus;
    #113;
    focus;
    $curbase= <clipboard>;
    $l = strlen ($curbase);
    $p = strpos ($curbase, <crlf>);
   $curbase = regexreplace ($curbase, "^-1$", "$l");
    if ($p = "-1") { $p = $l ; }
    $curbase = substr ($curbase, 0, $p);
    $curbase = replace ($curbase," ","_");
   set $curbase, "$curbase.zip";
//Compress file with .zip. Name= base of file.
 openwith """$p_zip"" a -tzip $curbase" ;
"Convert into <curbase>.&7z : 7z"
 focus;
    #113;
    focus;
    $curbase= <clipboard>;
    $l = strlen ($curbase);
    $p = strpos ($curbase, <crlf>);
   $curbase = regexreplace ($curbase, "^-1$", "$l");
    if ($p = "-1") { $p = $l ; }
    $curbase = substr ($curbase, 0, $p);
    $curbase = replace ($curbase," ","_");
   set $curbase, "$curbase.7z";
//Compress file with .zip. Name= base of file.
 openwith """$p_zip"" a -t7z $curbase"
-
"&Extract contents of <curname> here : ext"
   //Extract content to folder Name= base of zip. aot= If files exist, autonumber new files.
 openwith """$p_zip"" x -aot"
"&Extract contents of <curname> to folder <curbase> : extf"
    openwith """$p_zip"" x -y -o* -aot <items>"
"&Extract contents of <curname> to other pane w renumber existing : extfop"
         $a =  get("path", i);
   openwith """$p_zip"" x -y -o$a -aot <items>" ;
"&Extract contents of <curname> to other pane  : extfopr"
         $a =  get("path", i);
   openwith """$p_zip"" x -y -o$a  <items>" ;
"&Extract contents of <curname> to <curbase> other pane  : extfopra"
         $a =  get("path", i);
   openwith """$p_zip"" x -y -o$a\<curbase>\  <items>" ;
"&Extract contents of <curname> to other pane w renumber archive file : extfopr"
         $a =  get("path", i);
   openwith """$p_zip"" x -y -o$a -aou <items>" ;
"&Extract contents of <curname> to <curbase> other pane w renumber archive file : extfopra"
         $a =  get("path", i);
   openwith """$p_zip"" x -y -o$a\<curbase>\ -aou <items>" ;
-
"Convert into <curbase>.zi&p (password protection) : pzip"
  focus;
    #113;
    focus;
    $curbase= <clipboard>;
    $l = strlen ($curbase);
    $p = strpos ($curbase, <crlf>);
   $curbase = regexreplace ($curbase, "^-1$", "$l");
    if ($p = "-1") { $p = $l ; }
    $curbase = substr ($curbase, 0, $p);
    $curbase = replace ($curbase," ","_");
   set $curbase, "$curbase.zip";
 $i = input  (Input password for zipfile, password);
//Compress with .zip and password protect archive.
 openwith """$p_zip"" a -tzip $curbase -p$i"
"Convert into <curbase>.7z (password protection) : p7z"
    focus;
    #113;
    focus;
    $curbase= <clipboard>;
    $l = strlen ($curbase);
    $p = strpos ($curbase, <crlf>);
   $curbase = regexreplace ($curbase, "^-1$", "$l");
    if ($p = "-1") { $p = $l ; }
    $curbase = substr ($curbase, 0, $p);
    $curbase = replace ($curbase," ","_");
   set $curbase, "$curbase.7z";
 $i = input  (Input password for zipfile, password);
//Compress with 7z and password protect and encrypt archive headers.
 openwith """$p_zip"" a -t7z $curbase -p$i -mhe"
"?Set Password to <curname> : zp"
   global ($p_zip);
 set $file, <curbase>;
 openwith """$p_zip"" e -aou";
 msg "wait until extract",1;
 focus;
 filter $file*;
 delete 0,0;
 sortby created, d;
 sel 1;
 sub pzip;
 filter
"?Set Password to <curname> : z7"
   global ($p_zip);
 set $file, <curbase>;
 openwith """$p_zip"" e -aou";
 msg "wait until extract",1;
 focus;
 filter $file*;
 delete 0,0;
 sortby created, d;
 sel 1;
 sub p7z;
 filter
-
"Edit script : edit"
            $ScriptFile = self  ("file");
       run "$p_note" $ScriptFile,w;
-
"Cancel"
"_Terminate";
             unset $p_zip;
             unset $p_Zip;

EDIT: Added screenshot
03-07-2014 13-40-39.png
03-07-2014 13-40-39.png (109.18 KiB) Viewed 4351 times

HTH

Cheers,
Michael

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 16:14
by Stef123
aurumdigitus wrote: Anyway, as no one has come forward with a custom XYS ...
:?: :?: :?: Your request: "...a CTB that will take the selected Zip, create a folder with the same name and then put the extracted files in there?"
klownboy's answer (about Extractor): "It will unzip the current file into a new folder with the name of the zip file."
aurumdigitus wrote:What XY is doing with Zips appears to be transparent
How can code behind the scenes - that you don't see - be transparent? In comparison to script code that you can read line by line? Not that you have to, though. Extractor will ask you for the location for your zipper software if it can't find it.

Be aware, however, that this setting is not necessarily portable :!: But that's not different from the way XY handles your zippers now - if it can't find the expected zipper on a system, it won't work.

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 20:09
by aurumdigitus
@ Stef123 - By Transparent meaning that nothing else had to do done on this end. If XY is doing its Zip thing by invoking some other software on the machine that is beyond my understanding.

Extractor seems to be a separate program that needs one of its required Zip utilizes to operate. Seems rather convoluted as opposed to staying within XY.

But then coding is not chemistry (which is my vocation). :)

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 20:36
by admin
mkolaski wrote:No idea where I found this, but I've got the following set up for handling zip files...
Thanks Michael, interesting stuff! One day I will have time for this...

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 21:17
by Pagat
Maybe i'm missing something, but the original question was:
aurumdigitus wrote:Can a script be written that can be placed into a CTB that will take the selected Zip, create a folder with the same name and then put the extracted files in there?
That's a simple script command:

Code: Select all

zip_extract();
Put a new user button onto the toolbar and paste the "zip_extract();" command into the "On left click:" box. Done. The selected zip file will be extracted into a subfolder with the zip files name.

(Of course, there is no error handling done. So you'll get script errors if an invalid file (no zip) is selected)

Re: Extracting a Zip file to a folder via CTB

Posted: 03 Jul 2014 21:40
by aurumdigitus
Yes, yes Pagat - that is it! Exactly what was desired. You are a sagacious individual.

Reminds me of a quotation by Charles Darwin: To see what every man has seen; to think what no man has thought.

zip_extract(); The distilled essence of simplicity. One word, fourteen characters.

:appl:

Re: Extracting a Zip file to a folder via CTB

Posted: 04 Jul 2014 09:23
by Stef123
aurumdigitus wrote:Yes, yes Pagat - that is it! ... The distilled essence of simplicity :appl:
Bull's eye - right on target. :appl:
Distillation 8) - an apt wording. So you're in chemistry, huh? I am impressed. Nothing more taxing than those formulas. Watching the teacher juggle flasks and vials fascinated me. But I never grasped the theory behind those cocktails - way over my head.

@ Michael
Quite some dropdown :shock: - won't help my situation (I extract small subsets only, need to get a preview instead of dumping thousands of files on disk every time) - but I can imagine this script being a great starting point to adapt and tweak to personal preference.