Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

root

  • 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:

root

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.