Personal computing discussed

Moderators: renee, Dposcorp

 
Usacomp2k3
Gerbil God
Topic Author
Posts: 23043
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL
Contact:

7-zip automation

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.
 
CampinCarl
Graphmaster Gerbil
Posts: 1363
Joined: Mon Jul 04, 2005 9:53 pm

Re: 7-zip automation

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 AB350M Gaming-3 | R7 1700X | 2x8 GB Corsair Vengeance DDR4-3200 (@DDR4-2933)| Samsung 960 Evo 1TB SSD | Gigabyte GTX1080 | Win 10 Pro x86-64
 
Scrotos
Graphmaster Gerbil
Posts: 1109
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

Thu Nov 15, 2012 3:30 pm

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

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: 1109
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

Thu Nov 15, 2012 3:45 pm

Ok, so from in a batch file:

@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: 1109
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

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.
 
Usacomp2k3
Gerbil God
Topic Author
Posts: 23043
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL
Contact:

Re: 7-zip automation

Thu Nov 15, 2012 4:05 pm

Apparently the latest beta has a -m command. Going to try it soon.
 
Scrotos
Graphmaster Gerbil
Posts: 1109
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

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
 
Usacomp2k3
Gerbil God
Topic Author
Posts: 23043
Joined: Thu Apr 01, 2004 4:53 pm
Location: Orlando, FL
Contact:

Re: 7-zip automation

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
 
Scrotos
Graphmaster Gerbil
Posts: 1109
Joined: Tue Oct 02, 2007 12:57 pm
Location: Denver, CO.

Re: 7-zip automation

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.

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On