Quick tutorial on using 7-Zip to create compressed folders

This wikiHow article will show you how to use the free software 7-Zip to create multiple compressed folders in one go. This may come in handy for times when you are backing up your computer files or for whenever you need to compress a lot of file folders in general. This method involves using 7-Zip in a Windows batch file.

Steps

  1. 1
    Install 7-Zip. If you let it install using the default settings, it should typically be in "C:\Program Files\7-zip\7z.exe."
    • For this tutorial, let's say that you have some folders from your music collection that you want to compress so you can back them up on an external hard drive. These folders are contained inside a 'larger' folder named 'My Music.'
  2. 2
    Open the Notepad app. You won't need to use 7-Zip's graphical user interface, so no need to run it after installing.
    Advertisement
  3. 3
    In Notepad, insert this single line of code: for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\"
  4. 4
  5. 5
  6. 6
    Browse to the location of the folders you want to compress. In our example it is in C:\My Music.
  7. 7
  8. 8
    Click Save.
  9. 9
    Close Notepad and navigate to your 'My Music' folder. Notice that the batch file is at the same directory level as the folders that need to be compressed.
  10. 10
  11. 11
    Verify the validity of your compressed folders. To do this, highlight them all and click the right mouse button. If you installed 7-Zip in its default setting, you'll have its menu incorporated in the Windows shell. Navigate to it and click 'Test Archive.'
  12. Advertisement

Community Q&A

  • Question
    How can I zip only certain file types (e.g. PDF) across multiple folders/sub-folders?
    Community Answer
    Community Answer
    Create a bat file with the following command (replace pdf with desired extension): FOR %%i IN (*.pdf*) DO "c:\Program Files\7-Zip\7z.exe" a "%%~ni.zip" "%%i".
  • Question
    What if the folder names have spaces?
    Community Answer
    Community Answer
    Spaces in the folder names did not cause any issues for me. Test it out on a few practice folders and you should be able to tell if there are any issues.
  • Question
    Can a bunch of files be password-protected using a batch file?
    Community Answer
    Community Answer
    Yes; after the command, add the -p switch and then the password with no spaces between (i.e. "-ppassword"). Add -mhe on the end of that to encrypt the headers, which that means that whoever opens the zipped archive will have to provide a password to view its contents.
Advertisement

Things You'll Need

  • A computer with the Windows operating system.
  • 7-Zip, which you can download from here.
  • A text editor for creating the batch file, Windows Notepad is enough.

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 12 people, some anonymous, worked to edit and improve it over time. This article has been viewed 316,365 times.
How helpful is this?
Co-authors: 12
Updated: March 28, 2023
Views: 316,365
Categories: File Manipulation
Advertisement