0

I have the follwing command:

for %f in (*.txt) do "C:\WINDOWS\7za.exe" a -t7z "%f.7z" "%f"

which i send to a cmdprompt from a vba script. This works, but now I have to include the path to the folder on which to perform the zipping. I do this:

for %f in (usebackq "C:\Bob\WithBlank\NeuerOrdner3\" *.txt) do "C:\WINDOWS\7za.exe" a -t7z "%f.7z" "%f"

Why do i get one single zip file containing all *.txt files instead of one zip per txt file?

Lumpi
  • 2,697
  • 5
  • 38
  • 47

2 Answers2

0

I don't know why your second command line puts all files into a single archive, but the usebackq doesn't belong inside the parentheses. This should work:

for %f in ("C:\Bob\WithBlank\NeuerOrdner3\*.txt") do (
  "C:\WINDOWS\7za.exe" a -t7z "%~dpnf.7z" "%~ff"
)
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Tried it, simply nothing happens. Not even an Error message ? – Lumpi Feb 22 '13 at 13:24
  • When I try it in a powershell i get "Missing opening '(' after keyword 'for'." Why! – Lumpi Feb 22 '13 at 14:24
  • @Lumpi Because CMD is not PowerShell. If you ran my code in CMD and it didn't do anything at all, then either your path doesn't exist or it doesn't contain .txt files. – Ansgar Wiechers Feb 22 '13 at 17:05
0

Run it from .BAT file:

for %%a in (*.xml) do "\Program Files\7-Zip\7z.exe" a "%%~na.7z" "%%a"

7z file will have same name as original file

Брайков
  • 147
  • 2
  • 10