Compress files into individual archives

I needed to compress a lot of files into individual zip archives – I did not want to do it manually 🙂

Add the following to a bat file and every file with the extension txt will be compressed into a Zip archive with 7-Zip file archiver:

@echo off
For %%f in (*.txt) do 7z.exe a -tzip %%f.zip %%f

E.g. a.txt will be compressed to the archive a.txt.zip

This was not exactly what I needed, as the dual extension caused problems in later processing. In needed to remove the extension preceding the zip extension – therefore:

@echo off
For %%f in (*.txt) do 7z.exe a -tzip %%~nf.zip %%f

E.g. a.txt will be compressed to the archive a.zip

That’s it 🙂