Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

   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
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

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

for /F %%f in ('dir /s /b *.bak') do (
  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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.