7-zip automation

The place for all kinds of software for all kinds of operating systems.

Moderator: Dposcorp

7-zip automation

Postposted on Wed Nov 14, 2012 9:05 pm

Looking to do some compacting of data. Basically what I'm looking for is some lines of code I can throw into a batch file to compress some folders. The input would be the folder name (manually typed is fine). The result of running the script is that the folder would be compressed to a zip file and then the original folder deleted. The tricky part is that I need it to perform some sort of verification that all the contents of the folder were successfully put into the zip file prior to deletion. I don't see a flag for doing this in 1 step within the 7-zip command flags. I also am not sure what the best way to the verification.
I'm open to using another program to do thus, but in-place usage without installation is preferable.
Usacomp2k3
Gerbil God
 
Posts: 21294
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL

Re: 7-zip automation

Postposted on Wed Nov 14, 2012 9:12 pm

While I'm not particularly familiar with 7-zip's command line, I know it's possible as I did it ages ago. I can't find the batch files I wrote (were actually automated backup scripts), but this link is a good place to start. I know one of the command flags will let you do an update-and-verify type run.

Edit: After re-reading your post, I think you'll probably want to use the -l switch (which lists all the files in the archive), and then run a diff on that output to your original list.

Good luck! :)
Gigabyte Z77-DS3H | Core i7 3770 | 2x8 GB Crucial Ballistix DDR3-1600| Samsung 830 128GB SSD | Gigabyte HD7950 3GB | Win 7 Pro x86-64
CampinCarl
Graphmaster Gerbil
 
Posts: 1317
Joined: Mon Jul 04, 2005 9:53 pm

Re: 7-zip automation

Postposted on Thu Nov 15, 2012 3:30 pm

I don't know enough about the FOR command, but...

Code: Select all
dir | FIND "File(s)"
7z t test.zip | FIND "Files: "

C:\Program Files\7-Zip>dir | FIND "File(s)"
              17 File(s)      3,047,744 bytes
C:\Program Files\7-Zip>7z t test.zip | FIND "Files: "
Files: 17


I saw some snippet like thus:

FOR /F "tokens=2" %X IN ('7z t test.zip ^| FIND "Files: "') DO @SET COUNT=%X

I'm guessing it was able to pull the "17" from the 7zip results. You can probably manipulate that to pull the right "token" from the DIR command, too. Stuff the result into different variables, then a simple IF to throw an error if the numbers are different. BTW, that FOR statement works from the command line. I'm trying to integrate it into a .bat now.

I use 7zip to compress some SQL dumps on a daily process, handy:

"C:\Program Files\7-Zip\7z" -pSECRETPASSWORD u -tzip c:\temp\backup.zip c:\temp\daily\ -mx=9 -mfb=256 -mpass=5 -mem=AES256

I do see some issues with files that are really large, like over 1 GB. Sometimes 7zip will leave a .zip.tmp file and not finish creating the ZIP. I haven't cared enough to really delve into that; might be limited RAM on the machine and messing with the parameters would help. If I OCD enough about the FOR thing, I'll post any findings I have.
Scrotos
Graphmaster Gerbil
 
Posts: 1035
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

Postposted on Thu Nov 15, 2012 3:45 pm

Ok, so from in a batch file:

Code: Select all
@echo off
FOR /F "tokens=2" %%X IN ('7z t test.zip ^| FIND "Files: "') DO SET ZIPCOUNT=%%X
echo %zipcount%

FOR /F "tokens=1" %%X IN ('dir ^| FIND "File(s)"') DO SET DIRCOUNT=%%X
echo %dircount%

IF %zipcount% == %dircount% (
echo yay
) ELSE (
echo boo
)


Hope this is of value. In the IF, you could replace the == with EQU if you want. I'm unsure how that works with string comparisons as those are strings, not numbers. It probably makes no practical difference if there is any to begin with.
Scrotos
Graphmaster Gerbil
 
Posts: 1035
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

Postposted on Thu Nov 15, 2012 3:53 pm

Last consideration. If you do it from a different directory, I am unsure if DIR will return an extra 2 "files" for . and .. in the listing. If so, adjust accordingly. Also, this does not take into account subdirectories or the contents thereof. If you are doing things more than one level deep, you've got more work cut out for you. Hopefully this gets you a starting point.

Ah, and since the method I posted uses 7zip's "test" command, you may be able to trap an ERRORLEVEL for another layer of checking.
Scrotos
Graphmaster Gerbil
 
Posts: 1035
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

Postposted on Thu Nov 15, 2012 4:05 pm

Apparently the latest beta has a -m command. Going to try it soon.
Usacomp2k3
Gerbil God
 
Posts: 21294
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL

Re: 7-zip automation

Postposted on Thu Nov 15, 2012 5:53 pm

Huh?

http://sourceforge.net/projects/sevenzi ... ic/6063877

7-Zip 9.30 alpha Copyright (c) 1999-2012 Igor Pavlov 2012-10-26

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]

<Commands>
a: Add files to archive
b: Benchmark
d: Delete files from archive
e: Extract files from archive (without using directory names)
h: Calculate hash values for files
l: List contents of archive
t: Test integrity of archive
u: Update files to archive
x: eXtract files with full paths
<Switches>
-ai[r[-|0]]{@listfile|!wildcard}: Include archives
-ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
-bd: Disable percentage indicator
-i[r[-|0]]{@listfile|!wildcard}: Include filenames
-m{Parameters}: set compression Method
-o{Directory}: set Output directory
-p{Password}: set Password
-r[-|0]: Recurse subdirectories
-scs{UTF-8 | WIN | DOS}: set charset for list files
-sfx[{name}]: Create SFX archive
-si[{name}]: read data from stdin
-slt: show technical information for l (List) command
-so: write data to stdout
-ssc[-]: set sensitive case mode
-ssw: compress shared files
-t{Type}: Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
-v{Size}[b|k|m|g]: Create volumes
-w[{path}]: assign Work directory. Empty path means a temporary directory
-x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
-y: assume Yes on all queries

It's had -m for a while, see my sample command line for -mx=9, -mfb=256, -mpass=5, -mem-AES256. In the docs I see nothing that seems to be what you want. Unless that's documented in some of the beta/alpha release threads, he kinda spreads the new info around in each thread and I haven't followed many of them. If you find something, post back! :D
Scrotos
Graphmaster Gerbil
 
Posts: 1035
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

Postposted on Thu Nov 15, 2012 6:03 pm

An actual 'm' command, not a '-m' switch.

EDIT: Seems to work great. And apparently it's a branch beta, not in the main development...
http://sourceforge.net/projects/sevenzi ... ic/3957405
Usacomp2k3
Gerbil God
 
Posts: 21294
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL

Re: 7-zip automation

Postposted on Fri Nov 16, 2012 10:02 am

A "move" command, huh? Yeah, that sounds like a better solution than cobbling together some batch scripts. Hopefully that feature one day makes it into the main program.
Scrotos
Graphmaster Gerbil
 
Posts: 1035
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.


Return to General Software

Who is online

Users browsing this forum: No registered users and 3 guests