Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

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

   del "%%f"
share|improve this question
1  
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

2 Answers 2

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

 
discard

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.