To Create a batch to archive and delete a folder, first, we need 7zip to be installed on your computer. You can download the latest version of 7zip here.
After installing 7zip, save following commands to a text file and save it as
@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
remin front of delete folder line. After testing that this script works fine on your computer, you can remove
remin front of
rmdirline (one before last line) to enable deleting of folder.
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
If you liked this post, please share it! Enjoy!