7zip basic script

Discuss and share scripts and script files...
admin
Site Admin
Posts: 64862
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: 7zip basic script

Post by admin »

eurytos wrote:This is a little late and possibly slightly ot but I have a UDC setup using 7-zip that extracts archive(s) into folders based on the archive name. A little warning though, it will overwrite any files of the same name if there is already an existing folder with the archive's name without a prompt.


It works fine with single/multiple selections and it also works when drawing a rectangle around multiple items.
The path assumes you installed 7-zip to program files\7-zip so modify accordingly.

"C:\Program Files\7-Zip\7z.exe" x -y -o* <items>
Just to make sure: That's a UDC of type Open With.

eurytos
Posts: 200
Joined: 29 Jan 2008 15:53

Re: 7zip basic script

Post by eurytos »

admin wrote:
eurytos wrote:This is a little late and possibly slightly ot but I have a UDC setup using 7-zip that extracts archive(s) into folders based on the archive name. A little warning though, it will overwrite any files of the same name if there is already an existing folder with the archive's name without a prompt.


It works fine with single/multiple selections and it also works when drawing a rectangle around multiple items.
The path assumes you installed 7-zip to program files\7-zip so modify accordingly.

"C:\Program Files\7-Zip\7z.exe" x -y -o* <items>
Just to make sure: That's a UDC of type Open With.

yes,

sorry I should have been more specific.

admin
Site Admin
Posts: 64862
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: 7zip basic script

Post by admin »

eurytos wrote:
admin wrote:
eurytos wrote:This is a little late and possibly slightly ot but I have a UDC setup using 7-zip that extracts archive(s) into folders based on the archive name. A little warning though, it will overwrite any files of the same name if there is already an existing folder with the archive's name without a prompt.


It works fine with single/multiple selections and it also works when drawing a rectangle around multiple items.
The path assumes you installed 7-zip to program files\7-zip so modify accordingly.

"C:\Program Files\7-Zip\7z.exe" x -y -o* <items>
Just to make sure: That's a UDC of type Open With.

yes,

sorry I should have been more specific.
Once we have snippets (that's my favorite future feature!) it will be very easy to be 100% copy+paste-ready-specific! :)

lukescammell
Posts: 744
Joined: 28 Jul 2006 13:15
Location: Kent, UK
Contact:

Re: 7zip basic script

Post by lukescammell »

This (UDC > Open With command) doesn't seem to work with multiple files for me... (XY 7.70.0004) ...does it work for anyone else? Works fine on single files...
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

lukescammell
Posts: 744
Joined: 28 Jul 2006 13:15
Location: Kent, UK
Contact:

Re: 7zip basic script

Post by lukescammell »

serendipity wrote:Hmmm strange, works here for me. Tried on a second PC now and works there too. What does stepping through scripts reveal?
Seems to do everything it needs to correctly right up until the final 7z.exe command where a command prompt flashes up so fast I can't read anything on it :/

Also, creating either a ZIP or 7Z file using the script creates filenames of "$curbase.zip" and "$curbase.7z" respectively.
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: 7zip basic script

Post by serendipity »

lukescammell wrote: Seems to do everything it needs to correctly right up until the final 7z.exe command where a command prompt flashes up so fast I can't read anything on it :/
If the last line in the code is this:
openwith """%programfiles%\7-Zip\7z.exe"" x -o$curpath -aot"
Change it to:
openwith """%programfiles%\7-Zip\7z.exe"" x -o""$curpath"" -aot"
:oops: Another quoting blunder by me.
lukescammell wrote: Also, creating either a ZIP or 7Z file using the script creates filenames of "$curbase.zip" and "$curbase.7z" respectively.
I changed something, try these:

Code: Select all

"&Zip files : zip"
   focus;
   #113; 
   focus;
   set $curbase, <clipboard>; 
   strlen $l, $curbase; 
   strpos $p, $curbase, <crlf>; 
   regexreplace $p, $p, "^-1$", "$l"; 
   substr $curbase, $curbase, 0, $p;
   replace $curbase, $curbase," ","_"; 
   //Compress file with .zip. Name= base of file.
   openwith """%programfiles%\7-Zip\7z.exe"" a -tzip ""$curbase.zip"""
 
"&7z files : 7z"
   focus;
   #113; 
   focus;
   set $curbase, <clipboard>; 
   strlen $l, $curbase; 
   strpos $p, $curbase, <crlf>; 
   regexreplace $p, $p, "^-1$", "$l"; 
   substr $curbase, $curbase, 0, $p;
   replace $curbase, $curbase," ","_"; 
   //Compress file with .7z. Name= base of file.
   openwith """%programfiles%\7-Zip\7z.exe"" a -t7z ""$curbase.7z"""

lukescammell
Posts: 744
Joined: 28 Jul 2006 13:15
Location: Kent, UK
Contact:

Re: 7zip basic script

Post by lukescammell »

Interesting.

The second bunch of stuff now creates files named from the top most file or directory selected.

Just trying the first thing...
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: 7zip basic script

Post by serendipity »

lukescammell wrote:Interesting.

The second bunch of stuff now creates files named from the top most file or directory selected.
Yes, that was intentional. If you want the name of current folder instead then its lot easier:

Code: Select all

"&Zip files : zip"
   set $curfolder, <curfolder>; 
   //Compress file with .zip. Name= base of file.
   openwith """%programfiles%\7-Zip\7z.exe"" a -tzip ""$curfolder.zip"""

Code: Select all

"&7z files : 7z"
   set $curfolder, <curfolder>; 
   //Compress file with .zip. Name= base of file.
   openwith """%programfiles%\7-Zip\7z.exe"" a -t7z ""$curfolder.7z"""

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: 7zip basic script

Post by serendipity »

I updated the 7-zip script. Download and place it inside XY's scripts folder.
Download:
7zip.xys
(2.68 KiB) Downloaded 313 times

pseudoz
Posts: 60
Joined: 11 Mar 2009 20:41
Contact:

Re: 7zip basic script

Post by pseudoz »

Little improvements (Zip Multiple Folders & Unzip Selected Zip Files)
Not really optimized but fully fonctionnal :wink:

Code: Select all

"Zip Multiple Folders : zipmultiple"
  global $g_count, $g_items;
  $filter = getinfo("SelectedItemsPathNames", "|");
  replace $filter, $filter, "<curpath>\","";
  filter $filter;
  sel a;
  $g_items= getinfo("CountSelected");
  $g_count=1;
  copytext "";
  sub "_eval2";
  
"_eval2"
  global $g_count, $g_items;
  $updateitems= $g_items-$g_count;
  sel 1;
  focus;
  copytext "";
  copytext <curpath>\<curname>, a;
  set $curbase, <clipboard>; 
  strlen $l, $curbase; 
  strpos $p, $curbase, <crlf>; 
  regexreplace $p, $p, "^-1$", "$l"; 
  substr $curbase, $curbase, 0, $p;
  set $curbase, "$curbase.zip";
  run """<xypath>\Tools\Portable\7-Zip\7z.exe"" a ""$curbase"" -tzip ""<curpath>\<curname>""", , 1;
  delete 0,0,<curpath>\<curname>;
  $check=$updateitems < 1 ? "_start2" : "_count2";
  sub $check;
 
"_count2"
  global $g_count;
  $g_count=$g_count+1;
  sub "_eval2";

"_start2"    
  filter;
   
"Unzip Selected Zip Files : unzipmultiple"
  global $g_count, $g_items;
  $filter = getinfo("SelectedItemsPathNames", "|");
  replace $filter, $filter, "<curpath>\","";
  filter $filter;
  sel a;
  $g_items= getinfo("CountSelected");
  $g_count=1;
  copytext "";
  sub "_eval";
  
"_eval"
  global $g_count, $g_items;
  $updateitems= $g_items-$g_count;
  sel 1;
  focus;
  copytext "";
  copytext <curpath>\<curname>, a;
  run """<xypath>\Tools\Portable\7-Zip\7z.exe"" x ""<curpath>\<curname>"" -o""<curpath>"" -y", , 1;
  delete 0,0,<curpath>\<curname>;
  $check=$updateitems < 1 ? "_start" : "_count";
  sub $check;
 
"_count"
  global $g_count;
  $g_count=$g_count+1;
  sub "_eval";

"_start"    
  filter;

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: 7zip basic script

Post by serendipity »

pseudoz wrote:Little improvements (Zip Multiple Folders & Unzip Selected Zip Files)
Not really optimized but fully fonctionnal :wink:
Hi and Welcome to XY,
I havent checked out your script yet, but nice to see the more people are digging into scripting. Thats always a good sign. Enjoy XY and scripting. :)

lukescammell
Posts: 744
Joined: 28 Jul 2006 13:15
Location: Kent, UK
Contact:

Re: 7zip basic script

Post by lukescammell »

serendipity wrote:I updated the 7-zip script. Download and place it inside XY's scripts folder.
Download:
7zip.xys
Thanks serendipity - this is working great.

I tried your modified script pseudoz, but it errors out when even trying to compress small files (Vista SP1 x64)

Code: Select all

Error 	28 (0000001C)
Desc	Out of stack space
Dll	0
Proc	script_Process

Source	XYplorer
XY ver	8.20.0000
OS	Windows Vista (Service Pack 1)
Date	21/08/2009 10:15:04
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

totmad1
Posts: 131
Joined: 24 Jun 2013 12:37

Re: 7zip basic script

Post by totmad1 »

I came across these pages and thought I would add something.
1. listings
2. extract to other pane (various)

Code: Select all

"_Initialize";
	perm $p_zip = "C:\Users\user\Documents\portaprogs\7-ZipPortable\App\7-Zip64\7z.exe";
	perm $p_Zip = "C:\Users\user\Documents\portaprogs\7-ZipPortable\App\7-Zip64\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;

One problem I came across was the password sections but I don't use them on archives.

totmad1 (totally mad one)
totmad1 (totally mad one)

mithrin
Posts: 15
Joined: 15 Jan 2012 01:56

Re: 7zip basic script

Post by mithrin »

Hi, I like the idea of your script. Did you test it, because I'm getting all sort of errors.

Error list
00 works
1. OK
2. folder.txt empty
3. no file just a flick of cmd window
4. just a flick of cmd window, no chance to set destination.
5. zip convert in 7z, converts zip.zip inside 7zip, I would of thought it should of unpack the zip and repack as 7zip.
6. same as 5.
7. just a flick of cmd window
8. just a flick of cmd window
9. just a flick of cmd window
10. just a flick of cmd window
11. just a flick of cmd window
12. just a flick of cmd window
13. just a flick of cmd window
14. Password works but dose the same 5,6
15. Same as 14, If you press the wrong menu item (like number 14 instead of 15 whired thing happen)
16. Password works, unpacks and repacks OK but leaves the unpack ed files behind on disk, dose not delete.
17. same as 15
18. Crashes, dose not bring up edit of script
19 works

Any way thank you.

totmad1
Posts: 131
Joined: 24 Jun 2013 12:37

Re: 7zip basic script

Post by totmad1 »

Hi mithrin
In reply to your post . I had been using it and had found no problems.
So I did some extensive testing . one problem I found was I mainly use win7.
As a result I have no spaces in my paths .
This is where it gets interesting trying to find work arounds for XP.
I found that paths to 7z.exe could not contain spaces (wasn't clever with dots either).

This is the script I found worked in XP and win7 as long as the caveat was adhered to.

Code: Select all

"_Initialize";
// this has been tested on win7 64bit  and XP
	// Please make sure that path to 7z.exe does not contain spaces
        perm $p_zip = "C:\TEMP\New_Folder\7-Zip\7z.exe";
        perm $p_ZipFM = "C:\TEMP\New_Folder\7-Zip\7zFM.exe";
        perm $p_note  = """C:\Documents and Settings\Administrator\My Documents\ConTEXT\ConTEXT.exe""";
"&Open <curname> : open"
	 openwith "$p_ZipFM";
- 
"&List all this folder "
		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"
		Run("cmd /c $p_zip l ""<curitem>"" >""<curitem>.txt"" " );
-
"7-Zip and move into <curbase>.&7z and move : 7z"
		$a =  get("path", i);
	openwith """$p_zip"" a -t7z ""$a\<curbase>.7z""";
"Zip and move into <curbase>.&zip and move : zip" 
		$a =  get("path", i);
	openwith """$p_zip"" a -tzip ""$a\<curbase>.zip""";	
-
"Compress 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""" ;
"Compress 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 (prompts) : ext"
	 openwith """$p_zip"" x "
"&Extract contents of <curname> to folder <curbase> (overwrite NO warning) : extf"
	 openwith """$p_zip"" x -y -o*  <items>"
"&Extract contents of <curname> to other pane (overwrite NO warning) : extop"
	      $a =  get("path", i);
	openwith """$p_zip"" x -y -o""$a""  ""<items>""" ;
"&Extract contents of <curname> to <curbase> other pane (overwrite NO warning) : extfop"
	      $a =  get("path", i);
	openwith """$p_zip"" x -y -o""$a\<curbase>\""  <items>" ;
"&Extract contents of <curname> here w renumber existing : extre"
	//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> w renumber existing : extfre"
	 openwith """$p_zip"" x -y -o* -aot <items>"
"&Extract contents of <curname> to other pane w renumber existing : extopre"
	      $a =  get("path", i);
	openwith """$p_zip"" x -y -o""$a"" -aot <items>" ;

"&Extract contents of <curname> to other pane w renumber archive file : extopra"
	      $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>" ;
-
"Compress 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"
"Compress 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> zip : zp"
	 set $file, <curbase>;
         openwith """$p_zip"" x -y ""<items>""" ;
         msg "wait until extract",1;
         focus;
         filter $file*;
         wait 1000 ;
         delete 0, 0 ;
          sortby created, d;
          sel 1;
          sub pzip;
          filter $file;
"?Set Password to <curbase> .7z : z7"
      set $file, <curbase>;
      openwith """$p_zip"" x -aou ""<items>""";
      msg "wait until extract",1;
      focus;
      filter $file*;
      wait 1000 ;
      delete 0, 0 ;
      sortby created, d;
      sel 1;
      sub p7z;
      filter $file;
-
"Edit script : edit"

              $ScriptFile = self ("file");
              run $p_note """$ScriptFile""" , w;
-
"Cancel"
"_Terminate";
              //  unset $p_ZipFM;
              //  unset $p_zip;
              //  unset $p_note;
please dont be afraid to ask if there are any problems. As you can tell I enjoy the challenge.
I apologize for the delay in responding due to being unwell and all the testing it took.
Also added a couple more extracts and titled others differently.

totmad1 (totally mad one)
totmad1 (totally mad one)

Post Reply