Zip and Delete Folder Using 7zip
To Create a batch to archive and delete a folder, first, we need 7zip to be installed on our computer. You can download the latest version of 7zip here.
After installing 7zip, copy following commands to a text file and save it as archive.bat
:
@echo off rem Echo what exactly we are doing echo "C:\Program Files\7-Zip\7z.exe" a -r -tzip "%~nx1.zip" -mx9 "%~f1\*.*" rem Run 7zip with arguments "C:\Program Files\7-Zip\7z.exe" a -r -tzip "%~nx1.zip" -mx9 "%~f1\*.*" rem Delete folder silently rem rmdir /s/q "%~f1" pause
Caution: If you don’t have 7zip installed on your computer, this script will only delete your folder. So I added
rem
in front of delete folder line (rmdir /s/q "%~f1"
). After testing that this script works fine on your computer, you can removerem
in front ofrmdir
line to enable deletion of the folder.
Usage
Drop any directory on the batch file, it will create a zip archive and delete that folder.
Similarly, you can use -mx0
argument to just store your folder without compression.
If you don’t want to delete your folder just remove rmdir
line.
If you liked this post, please share it! Enjoy!