Page 1 of 3

7zip basic script

Posted: 11 Jul 2008 18:53
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.

Posted: 11 Jul 2008 22:25
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"
 

Re: 7zip basic script

Posted: 03 Sep 2008 04:22
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;

Re: 7zip basic script

Posted: 03 Sep 2008 08:01
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'

Re: 7zip basic script

Posted: 03 Sep 2008 14:54
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";

Re: 7zip basic script

Posted: 03 Sep 2008 14:58
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!

Re: 7zip basic script

Posted: 03 Sep 2008 16:03
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;

Re: 7zip basic script

Posted: 03 Sep 2008 17:09
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"

Re: 7zip basic script

Posted: 03 Sep 2008 17:51
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

Re: 7zip basic script

Posted: 04 Sep 2008 00:41
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 :/

Re: 7zip basic script

Posted: 04 Sep 2008 05:49
by serendipity
Hmmm strange, works here for me. Tried on a second PC now and works there too. What does stepping through scripts reveal?

Re: 7zip basic script

Posted: 04 Sep 2008 08:22
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.

Re: 7zip basic script

Posted: 05 Sep 2008 03:41
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? :)

Re: 7zip basic script

Posted: 05 Sep 2008 07:45
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.

Re: 7zip basic script

Posted: 09 Sep 2008 22:22
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>