7zip basic script

Discuss and share scripts and script files...
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

7zip basic script

Post by serendipity »

Donot use this script, see next post.

I made some simple scripts for compressing and extracting files with 7zip, here is the script file:

//7-Zip script files
"Open Zipfile : open"
openwith "%programfiles%\7-Zip\7zFM.exe"
-
"&Zip files : zip"
//Compress file with .zip. Name= base of file.
openwith """%programfiles%\7-Zip\7z.exe"" a -tzip "<curbase>""

"&7z files : 7z"
//Compress file with .7z. Name= base of file.
openwith """%programfiles%\7-Zip\7z.exe"" a -t7z "<curbase>""

"&Extract : ext"
//Extract content to folder Name= base of zip.
openwith """%programfiles%\7-Zip\7z.exe"" x -aot"
-
"Zi&p files (with password) : pzip"
input $i, Input password for zipfile, password;
//Compress with .zip and password protect archive.
openwith """%programfiles%\7-Zip\7z.exe"" a -tzip "<curbase>" -p$i"

"7z files (&with password) : p7z"
input $i, Input password for zipfile, password;
//Compress with 7z and password protect and encrypt archive.
openwith """%programfiles%\7-Zip\7z.exe"" a -t7z "<curbase>" -p$i -mhe"


These are ofcourse very basic because with 7zip you can control lot of things like level of compression, self-extracting archives etc.
Last edited by serendipity on 18 Sep 2008 21:56, edited 1 time in total.

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

Post by serendipity »

Update: 23 Oct '08

The above script will not work if you make selections using selection rectangle. See here. With some help from Jacky, I am updating the above script.

Code: Select all

//7-Zip script files
"Open Zipfile : open"
   openwith "%programfiles%\7-Zip\7zFM.exe"
- 
"&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"""

- 
"&Extract : ext"
  //Extract content to folder Name= base of zip. aot= If files exist, autonumber new files.
   openwith "%programfiles%\7-Zip\7z.exe" x -aot

"&Extract (to folder) : extf"
   // Copy item/pathname to cilpboard
   openwith """C:\Program Files\7-Zip\7z.exe"" x -y -o* -aot <items>"
-
"Zi&p files (with password) : pzip"
   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," ","_"; 
   set $curbase, "$curbase.zip";
   input $i, Input password for zipfile, password;
   //Compress with .zip and password protect archive.
   openwith """%programfiles%\7-Zip\7z.exe"" a -tzip $curbase -p$i"
  
"7z files (&with password) : p7z"
   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," ","_"; 
   set $curbase, "$curbase.7z";
   input $i, Input password for zipfile, password;
  //Compress with 7z and password protect and encrypt archive headers.
   openwith """%programfiles%\7-Zip\7z.exe"" a -t7z $curbase -p$i -mhe"
 
Last edited by serendipity on 24 Oct 2008 04:32, edited 5 times in total.

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

Re: 7zip basic script

Post by lukescammell »

Code: Select all

"&Extract : ext"
 //Extract content to folder Name= base of zip.
 //aot= If files exist, autonumber new files.
 openwith """%ProgramW6432%\7-Zip\7z.exe"" x -aot -o./newly-extracted-files"
This extracts the contents of the archive to a folder called "newly-extracted-files" in the same location as the archive. How can I get this "newly-extracted-files" folder to be named by the name of the archive file being extracted?

P.S. Don, you need to change your style sheets as the forum is stripping out white space from the code examples! Change white-space: normal; to white-space: pre;
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

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

Re: 7zip basic script

Post by admin »

lukescammell wrote:P.S. Don, you need to change your style sheets as the forum is stripping out white space from the code examples! Change white-space: normal; to white-space: pre;
Great, that was easy! :D

Here's a tip for you. Use outer single quotes to avoid the need to double the double quotes:

Code: Select all

OLD: openwith """%ProgramW6432%\7-Zip\7z.exe"" x -aot -o./newly-extracted-files"
NEW: openwith '"%ProgramW6432%\7-Zip\7z.exe" x -aot -o./newly-extracted-files'

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

Re: 7zip basic script

Post by admin »

admin wrote:
lukescammell wrote:P.S. Don, you need to change your style sheets as the forum is stripping out white space from the code examples! Change white-space: normal; to white-space: pre;
Great, that was easy! :D
I had to take it back! :( Copying the code from the browser did lose all line breaks with this setting.

Code: Select all

set $a, "it is <date hh:nn:ss>";
  $b = "it is <date hh:nn:ss>";
  msg "$a<br>$b";

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

Re: 7zip basic script

Post by admin »

admin wrote:
lukescammell wrote:P.S. Don, you need to change your style sheets as the forum is stripping out white space from the code examples! Change white-space: normal; to white-space: pre;
Great, that was easy! :D
I had to take it back! :( Copying the code from the browser did lose all line breaks with this setting.

However, I found that I have no problems keeping white space without white-space: pre. See this (copied from UltraEdit, real white space, no tabs):

Code: Select all

set $a, "it is <date hh:nn:ss>";
  $b = "it is <date hh:nn:ss>";
  msg "$a<br>$b";
So the problem must have another cause!

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: 7zip basic script

Post by jacky »

Well, I know I noticed that the first spaces were eaten up, so I always try to put two spaces at the beginning of each line, cause then they remain. See:

Code: Select all

"single space"
 set $a, "foobar";
 msg $a;
"double space"
  set $a, "foobar";
  msg $a;
As for the cause of this, might be that phpBB that doesn't convert single space to &nbsp;
Proud XYplorer Fanatic

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

Re: 7zip basic script

Post by serendipity »

lukescammell wrote:

Code: Select all

"&Extract : ext"
 //Extract content to folder Name= base of zip.
 //aot= If files exist, autonumber new files.
 openwith """%ProgramW6432%\7-Zip\7z.exe"" x -aot -o./newly-extracted-files"
This extracts the contents of the archive to a folder called "newly-extracted-files" in the same location as the archive. How can I get this "newly-extracted-files" folder to be named by the name of the archive file being extracted?
This is a bit longer script but will extract the archive to the folder with the same name.

Code: Select all

"&Extract (to folder) : extf"
 //Copy item/pathname to clipboard
  #101; 
  focus; 
  set $toextract, <clipboard>; 
  focus;
 //Copy item base to clipboard
  #113; 
  focus;
  set $curbase, <clipboard>; 
 //Create new folder based on archive's name
  new $curbase, dir;
  set $curpath, <curitem>;
  goto $toextract;
 //Extract content to folder Name= base of zip. aot= If files exist, autonumber new files.
  openwith """%programfiles%\7-Zip\7z.exe"" x -o"$curpath" -aot"

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

Re: 7zip basic script

Post by admin »

jacky wrote:Well, I know I noticed that the first spaces were eaten up, so I always try to put two spaces at the beginning of each line, cause then they remain. See:

Code: Select all

"single space"
 set $a, "foobar";
 msg $a;
"double space"
  set $a, "foobar";
  msg $a;
As for the cause of this, might be that phpBB that doesn't convert single space to &nbsp;
Aha! Good find! :D

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

Re: 7zip basic script

Post by lukescammell »

serendipity wrote:
lukescammell wrote:How can I get this "newly-extracted-files" folder to be named by the name of the archive file being extracted?
This is a bit longer script but will extract the archive to the folder with the same name.

Code: Select all

"&Extract (to folder) : extf"
 //Copy item/pathname to clipboard
  #101; 
  focus; 
  set $toextract, <clipboard>; 
  focus;
 //Copy item base to clipboard
  #113; 
  focus;
  set $curbase, <clipboard>; 
 //Create new folder based on archive's name
  new $curbase, dir;
  set $curpath, <curitem>;
  goto $toextract;
 //Extract content to folder Name= base of zip. aot= If files exist, autonumber new files.
  openwith """%programfiles%\7-Zip\7z.exe"" x -o"$curpath" -aot"
This is creating the folder, but not putting anything into it :/

Regarding the strangeness with the code boxes - none of the strangeness should be happeneing, it's wrong. The whole point of the code tags is that it isn't meant to change anything in the text... wierd :/
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 »

Hmmm strange, works here for me. Tried on a second PC now and works there too. What does stepping through scripts reveal?

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

Re: 7zip basic script

Post by admin »

lukescammell wrote:Regarding the strangeness with the code boxes - none of the strangeness should be happeneing, it's wrong. The whole point of the code tags is that it isn't meant to change anything in the text... wierd :/
They don't use <code> tags. It's a <div> with some properties.

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

Re: 7zip basic script

Post by lukescammell »

They do..

Code: Select all

<dl class="codebox"><dt>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></dt><dd><code>"&Extract (to folder) : extf"<br /> //Copy item/pathname to clipboard<br />&nbsp; #101; <br />&nbsp; focus; <br />&nbsp; set $toextract, <clipboard>; <br />&nbsp; focus;<br /> //Copy item base to clipboard<br />&nbsp; #113; <br />&nbsp; focus;<br />&nbsp; set $curbase, <clipboard>; <br /> //Create new folder based on archive's name<br />&nbsp; new $curbase, dir;<br />&nbsp; set $curpath, <curitem>;<br />&nbsp; goto $toextract;<br /> //Extract content to folder Name= base of zip. aot= If files exist, autonumber new files.<br />&nbsp; openwith """%programfiles%\7-Zip\7z.exe"" x -o"$curpath" -aot"<br /></code></dd></dl>
Unfortunately, they also do horrible, HORRIBLE things like put br tags in the code, GAH! No wonder there's all sorts of problems. PHPBB should know better (there shold only ever be text inside code tags, that's supposed to be the whole point)...

Back OT a bit, but is there a way to make this script popup when I right click on a 7z and/or rar/zip/etc file? :)
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

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

Re: 7zip basic script

Post by admin »

Oh yes, they do use <code>.
lukescammell wrote:Back OT a bit, but is there a way to make this script popup when I right click on a 7z and/or rar/zip/etc file? :)
Not yet. Will come with custom events.

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

Re: 7zip basic script

Post by eurytos »

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>

Post Reply