Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Under the folder images\, I have the following folders:

  • Usa\
  • Italy\
  • Japan\


I want a script that creates a .zip for each of these folders, so I have ,,

How can I do that?

share|improve this question
Would you prefer for it to run under OS/2 or under VMS? – Ignacio Vazquez-Abrams Jul 31 '11 at 8:11
I would help, but we really need to know the Operative System. Windows maybe? – nmat Jul 31 '11 at 8:43

I assume this is Windows, as you are using backslashes.

Get 7za.exe (the command-line version of 7-zip) and put it in your %PATH%.

Then run this within your Images\ directory:

for /f "usebackq" %G in (`dir /b /a:d "%cd%"`) do 7za a -r -tzip "" "%~G"

Or in a batch script:

for /f "usebackq" %%G in (`dir /b /a:d "%cd%"`) do 7za a -r -tzip "" "%%~G"
share|improve this answer

You can use Winrar for this.

Select all your folders, right click and select Add to archive. Now select the option Put each file to separate archive under the tab Files:

enter image description here

Click OK and you're done. If you want .zip files instead of .rar, just select ZIP in the General tab under Archive format.

share|improve this answer

Assuming you are on Linux you could use a Bash script like this:



  for f in $(find "$1" -mindepth 1 -maxdepth 1 -type d ); do
    zip -r "$f" "$f"

This script will take the first argument as folder, in this case images, and recurse exactly one level deep to get all your folders (Usa, Italy and Japan) and zip them in the same place.

It will not delete old zip files or the source folders. Zip is smart enough to detect existing zip files and update them when run again. However, if you delete a file in the source folders it will not be deleted in the zip files. You might circumvent this behaviour by deleting existing files beforehand.

share|improve this answer
I used the Linux script that sponiro posted, and added a line at the beginning to delete folders: find $1 -type d | xargs rm -rf – genevish Apr 15 '15 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .