Unzip all files in a folder using 7zip in CMD line

2020-03-05 02:24发布

问题:

i'm using these lines to extract all JAR files in a folder, destination can be the same one :

<b>set SEVENZIP_EXE=C:\Program Files\7-Zip\<br>
set INPUT_FOLDER=D:\jar

for /f "tokens=1-2 delims=. " %%a in ('dir *.jar /a-d/b') do "%SEVENZIP_EXE%" x -aoa -o"%INPUT_FOLDER%" %%a.%%b

But all what i got is : %%a was unexpected at this time. !!

any suggestion ?
Thanks

回答1:

You're running it in a command prompt, not on a batch file. If you're on a prompt, you should only use a single %:

set INPUT_FOLDER=D:\jar

for /f "tokens=1-2 delims=. " %a in ('dir *.jar /a-d/b') do "%SEVENZIP_EXE%" x -aoa -o"%INPUT_FOLDER%" %a.%b

I also noticed that you didn't set the path to 7-zip's executable properly:

set SEVENZIP_EXE=C:\Program Files\7-Zip\7z.exe

If it doesn't work perhaps try running it as a batch file

@echo off

set SEVENZIP_EXE=C:\Program Files\7-Zip\7z.exe
set INPUT_FOLDER=D:\jar

for /f "tokens=1-2 delims=. " %%a in ('dir *.jar /a-d/b') do "%SEVENZIP_EXE%" x -aoa -o"%INPUT_FOLDER%" %%a.%%b