How to make 7-zip do a whole bunch of folders
I got a bunch of pictures that I had to crop into 800x600 pixels. That was easily done, but now I have to upload them so the family can see them all.
Thing is, this is 500MB in pictures. I decided to simply zip the separate folders, which each contain an almost equal amount of pictures. This way I can upload a couple each day. Doing this manually is a very long and hard job. I wonder if there is a way to make 7-zip handle each folder individually?
I think I'll need a batch file to do it, but I'm not good with that. I've put everything under one folder. In the various subfolders is where the pictures are located. What I need is for the contents of that folder to be zipped. I'm not sure if I can just zip the folder along with it. I know PHP has a zip module, I've just never worked with it, so I'm not sure whether it can handle the fact that the content of the zip is a folder which contains the items, instead of just the items.
Solution 1:
Run from a command prompt whose working directory is your My Pictures
directory, this command will create a zip file of the contents of each subdirectory, leaving all of the zip files in your My Pictures
directory.
Edit: I have added the quotation marks necessary to allow for directories with spaces in their names.
for /D %%d in (*.*) do 7z a -tzip "%%d.zip" "%%d"
Also: The following version will not put files in a subdirectory inside of the zip file, but instead in its root:
for /D %%d in (*.*) do 7z a -tzip "%%d.zip" ".\%%d\*"
In Windows 7 and above
for /D %d in (*.*) do 7z a -tzip "%d.zip" "%d"
or
for /D %d in (*.*) do 7z a -tzip "%d.zip" ".\%d\*"
Solution 2:
I couldn't get the command line to work, instead I downloaded WinRAR and mtone was right - WinRAR does have an option to zip multiple folders into their own separate ZIP files.
E.g. C:\Files\Fables 01
into C:\Files\Fables 01.zip
, and C:\Files\Fables 02
into C:\Files\Fables 02.zip
.
With WinRAR, open the Folder that contains the folders you want to zip, then follow these steps:
- Select all folders you want zipped/rared
- Click "ADD" or Alt+A or Commands -> "Add files to Archive"
- Select RAR or ZIP
- go to "Files" tab
- Check "Put each file to separate archive" under the Archives box
When you've got any other settings you like fixed, hit OK and boom: multiple ZIP files of multiple folders. This worked so much easier than command line 7zip.
Solution 3:
Just a slight update of eleven81's answer: The code below creates a batch file which multiple items can be dropped onto.
@echo off
if [%1]==[] goto :eof
:loop
7z a -tzip "%~1.zip" "%~1"
shift
if not [%1]==[] goto loop
This batch file can then be added to the context menu via the registry:
- create a new key under [HKEY_CLASSES_ROOT\Folder\shell], call it cmd1
- Edit the string value and call it 'Batch Zip'
- create another new key under this one and call it command
- Change the value of this to your path, with double escaped slashes
So for example, my entry is "C:\Users\Rory\Dropbox\_apps\batch_zip.bat" "%1"
Once you do this you'll have an entry in your context menu for 'Batch Zip' which will batch zip any selected folders into separate archives
However, if you do this via the context menu, it will unfortunately run all operations simultaneously, and as anyone who's done a lot of zipping and unzipping will know, zipping folders works a lot faster one after the other than all at once.
If anyone knows a way to fix this in the registry please do tell.
Dragging the selected folders onto the batch will do them one after the other.