1

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"
stighy
  • 931
  • 8
  • 21
  • 32
  • 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 Answers2

1

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.

Tonny
  • 6,332
  • 1
  • 18
  • 31
1

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