I have a folder, lets say, MAIN. Inside this folder, there are many folders(say f1,f2,f2...) which has subfolders and files in them. Now I need to zip these folders(f1,f2,f3...) and their contents (which might be subfolders and files) into separate zips(f1.7z, f2.7z, f3.7z ...) and put them under MAIN folder.

Also, I need to use these settings for all the zips. .7z, LZMA2, Ultra, 1024MB(Dictionary size), 273(Word size), Solid, Compress shared files. How can I do this?


Running a basic batch compress job can be done thus. You will however need to edit the command as necessary to accommodate your specific requirements. This can be done through the use of various 'switches'; the syntax for doing so is available here.

  • I already checked that First link. It makes the output file to be in one single zip file, doesn't it? But Unfortunately, I don't want it that way. Thanks for the second link. Though it might take me weeks to find what i want by myself, I've no other way. If you already know how to do code to meet my requirements, please advise so.
    – pras92
    Mar 2 '13 at 18:22
  • 1
    @prashanth: The first link had actually worked fine for me. I just made a bat file with the contents as for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\" and put in in my MAIN folder. When I ran it, I got each folder in a separate 7z file. Mar 2 '13 at 19:43
  • Thank You Ron. I didn't read it properly. It works like a charm now. You saved me a lot of time. :)
    – pras92
    Mar 3 '13 at 19:25
  • 1
    @prashanth: Happy to help. :) Please do mark the answer as accepted if you're happy with it. Mar 3 '13 at 19:29
  • Oh. I didn't know that, expect for voting the answer. Thank You.
    – pras92
    Mar 3 '13 at 19:59

This should work reasonably well:

find -maxdepth 1 -type d -exec p7zip {} \;

You should be able to construct your final command line from that easily.

  • -maxdepth 1
    Only search 1 directory deep
  • -type d
    Only search for directories
  • -exec p7zip {} \;
    Pass every found item to p7zip - creating a .7z archive of the folder.
  • Actually, i'm not exposed to CLI. So would you please tell me the exact code to perform this? Also, if we are to keep maxdepth = 1, won't the files in the subfolders be excluded? And there is no mention of the settings that i intend to use. How do i specify that?
    – pras92
    Mar 2 '13 at 18:16
  • @prashanth: You'll need to use the command-line version of 7zip, the usage of which is documented in the 7zip Help file that comes with the executable -- should be listed under "Programs" from the Start menu.
    – martineau
    Mar 2 '13 at 20:12
  • p7zip of course is the command line version of 7-Zip for Unix/Linux. 7za.exe is what you'd use if you were on Windows.
    – Karan
    Mar 2 '13 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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