metinsaylan
metinsaylan
As an Amazon Associate, I earn from qualifying purchases.

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 remove rem in front of rmdir 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!

2 Comments

  • Metin Şaylan

    Thanks for your inputs! Updated the post accordingly <3

  • Kam

    rmdir /s/q "%~f1"
    This line didn't work for me without the quotes. Most likely caused by a space in my folder name.

Leave a Reply

Your email address will not be published.

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

More Snippets
Share Share Tweet