Take the 2-minute tour ×

I need to ZIP all files Bak inside a folder and subfolders, and at the end of each zipping job, delete the bak file. I wrote something like this, but it don't works:

   for /F %%f in ('dir /s /b *.bak') do goto=1

   "7za.exe" a -t7z -mx3 "%%f.zip" "%%f"

   del "%%f"
share|improve this question
Do you actually need a DOS batch file? Or do you need a batch file that will run on a modern Windows version? They're two different things. –  MDMarra Nov 16 '12 at 11:39
It is a .bat that run inside Windows 2008 Server –  stighy Nov 16 '12 at 11:46
add comment

2 Answers

up vote 1 down vote accepted

This should do it too, functional way:

for /F %%f in ('dir /s /b *.bak') do call :myfunc %%f
goto :eof
7za.exe a -t7z -mx3 "%1.7z" "%1"
del "%1"
goto :eof
share|improve this answer
add comment

From the top of my head, I'm not in a Windows environment at the moment so I can't verify:

  7za.exe a -t7z -mx3 "%%f.7z" "%%f"
  del "%%f"

Please note that I changed the extension on the file.
With -t7z you are creating a 7z file: Not a zip.
-mx9 will give you better compression by the way, but it will take quite a bit longer.

share|improve this answer
add comment

Your Answer


