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

can anyone help me make a batch file for my problem. i have multiple folders that i want to compress individually.


  • folder 1

    file 1
    file 2

  • folder 2
    file 1
    file 2

i need to go inside folder 1 first then zip all its contents (files and folders, even the subdirectories in it) then have the zip file named after the folder. after that, go to the folder 2 then do the same.

there was a simple script:

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X" "%%X\"

but the result is not is not what i intend to get. the above script will compress all the folders inside individually, but the archive will have double folder when extracted. the above code will compress folder 1. but when i extract folder 1 it will look like this:


folder 1

folder 1

file 1
file 2

can't it be like going inside the first folder, compress everythiing in it, save the zip file with the folders name then go to the next folder until it compressed everything.

share|improve this question
We should not be making this for you. You should be attempting this yourself and asking us to help fix whatever you have managed to do. We're here to help, not to do your work for you. – Mokubai Oct 16 '13 at 19:06

It depends on the command you use to extract.

If you choose "extract here" you'll get exactly what you want.

If however you really don't want the folder-names in your archive you can do the following:

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X" ".\%%X\*"

Note the .\%%X\*. This will exclude the directory-name itself.

share|improve this answer

You must log in to answer this question.

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