Friday, March 9, 2012

7-Zipping multiple folders to separate/individual zip/archive files

The problem was I had several folders I wanted to zip into individual 7z archives.  7-zip lacks a ‘Add to “*.7z”‘ explorer context for multiple selected files or folders (even though it does include a ‘Extract to “*\”‘).  Nor does this option appear within the application itself or via the command-line.  I seem to recall this feature being available in the Explorer contexts for some ZIP program I once used (I think it was TUGzip), but I wanted to choose quite aggressive compression settings for the archives and I didn’t think this would be achievable except via the command-line.
So using a bit of Google skills I discovered the ‘for… in… do’ batch command.  Which is quite powerful and I’m sure will come in handy again now that I know about it. Coupled with the 7-zip manual I arrived at a batch file with this line in it:

For 7z archive files

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\" -mx=9 -ms=on -md=26 -mfb=256
FOR RAR Archive files

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.rar" "%%X\" -mx=9 -ms=on -md=26 -mfb=256

So copy that into a batch file, copy it to the directory where you have folders you want to zip to individual archives and run it.  You might want to change (or just delete) the custom settings (e.g. the settings with -m at the end) as it set up to do some pretty heavy compression which does take quite a long time (but of course you can leave it running in the background without too much problem).

No comments:

Post a Comment