Zip folders to separate files

Zip folders to separate files

How to zip folders to separate files.

If you have a few folders and you want to create one archive for each folder.

Video how to steps.

Zip folders to separate files

Setup environment

How to create individually separate archives there is a way you can zip all folders to separate archives using the 7-Zip command line to you can install 7-Zip from the 7-zip website download page.

Once you have 7-Zip installed, you can run this command below in a batch file you can create a .bat file.

Auto zip folders script

The batch file contents are just text commands to run as part of the .bat script or batch file.

You can name the .bat file anything you like.

How to run it

To run the .bat file in the current directory where you have your folders ready.

Copy the .bat file next to your directories and double click to start to zip all folders into separate archives – folders in the current directory where the .bat file is saved.

Zip folders into separate archive files script

This is the script, please do NOT run this .bat script until you read ALL of this post.

You try this at your own risk, no liability accepted, no support.

for /d %%n in (*) do "%ProgramFiles%\7-Zip\7z.exe" a "%%n.zip" "%%n\"

The auto zip script explained:

for /d %%n in (*) do

It goes thru all directories in the current folder and does the next action.

“%ProgramFiles%\7-Zip\7z.exe” a “%%n.zip” “%%n\”

Calls 7-Zip to the default install location (you might have to change this) and passes parameters to 7-Zip in CLI mode – command line interface. Add / archive zip file name using target folder.

Then goes to the next folder and runs the same steps until there is are no more folders to archive left.

The script does not delete anything, it olny creates zip files from subfolders.

How I use it

The way I have it set up is the .bat script is in the folder where I keep the folders I want to be zipped.

It’s looking at all the current folders in the current folder where the script is saved and it will go through each folder creating a zip file archive for all the folders and the files inside the folders.

Most importantly to be sure it’s ok you’ll also want the files that are contained within this folders and afterwards, check the folders count.

I check the count of the zip files first you should also check try to extract a few of the zip files make sure that the zip file actually contains the correct files you want.

Once I make sure that all the files and folders were archived in the zip files.

I delete the archived folders and I move the zip files to the archive location.

This is the way I do it and hopefully this is helpful.

It’s a very simple Windows script using built-in functions of Windows.

Verify

There is nothing special about this. The most dangerous thing would be that it is not archiving all the files you want to archive so before you delete anything make sure that you have all your files from inside the zip folder to inside the zip file. First few tries, extract all zipped files and compare file/folder count with the original source folders.

Right click – properties on both and see file count and size. File count and size should be identical between source and extracted folder.

I really only checked the count to count of folders I checked if there are 10 photos that should be 10 files and the size is not too small for them I did two folders and I archive the files without too much trouble but the first time you tried to do this make sure you extract the zip files all of them actually extract all the files.

Make sure that all the parts are from folders you have so that there’s not one missing the first one or the last one is missing so the count should be the same of zip files and folders in the content should be the same after extracting them.

Hopefully this is helping you. Thanks for reading!

How to create zip files

How to Create a Zip File in Windows 10 or 11

Extract multiple archives in separate folders

How to extract multiple archives in separate folders in the same way as zipping.

All you have to do is make another .bat file call it anything you like extract_all.bat seems ok.

contents of the extract zip archives (untested) bat:

for /f %%n in (*.zip) 
do "%ProgramFiles%\7-Zip\7z.exe" x "%%n.zip" -o "%%n\"

this time we look for each file in the current directory /f that ends with .zip – you can change it to ” for all files.

Then run 7zip and pass the x argument to extract preserving full directory path and -o to set the output directory to a sub-folder with the same name as the zip archive file.

It’s easy to adjust both zip all folders and extract all archives scripts to fit your needs.

Enjoy your scripts!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.