用于解压缩目录中文件的 Windows 批处理脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17077964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows batch script to unzip files in a directory
提问by Mark Kennedy
I want to unzip all files in a certain directory and preserve the folder names when unzipped.
我想解压缩某个目录中的所有文件并在解压缩时保留文件夹名称。
The following batch script doesn't quite do the trick. It just throws a bunch of the files without putting them into a folder and doesn't even finish.
以下批处理脚本并不能完全解决问题。它只是抛出一堆文件而不将它们放入文件夹中,甚至没有完成。
What's wrong here?
这里有什么问题?
for /F %%I IN ('dir /b /s *.zip') DO (
"C:\Program Files (x86)-Zipz.exe" x -y -o"%%~dpI" "%%I"
)
回答by Ansgar Wiechers
Try this:
尝试这个:
for /R "C:\root\folder" %%I in ("*.zip") do (
"%ProgramFiles(x86)%-Zipz.exe" x -y -o"%%~dpI" "%%~fI"
)
or (if you want to extract the files into a folder named after the Zip-file):
或者(如果要将文件解压缩到以 Zip 文件命名的文件夹中):
for /R "C:\root\folder" %%I in ("*.zip") do (
"%ProgramFiles(x86)%-Zipz.exe" x -y -o"%%~dpnI" "%%~fI"
)
回答by Billy Scott
Ansgar's response above was pretty much perfect for me but I also wanted to delete archives afterwards if extraction was successful. I found thisand incorporated it into the above to give:
Ansgar 上面的回复对我来说非常完美,但如果提取成功,我也想在之后删除档案。我找到了这个并将其合并到上面给出:
for /R "Destination_Folder" %%I in ("*.zip") do (
"%ProgramFiles%-Zipz.exe" x -y -aos -o"%%~dpI" "%%~fI"
"if errorlevel 1 goto :error"
del "%%~fI"
":error"
)
回答by foxidrive
Try this.
尝试这个。
@echo off
for /F "delims=" %%I IN (' dir /b /s /a-d *.zip ') DO (
"C:\Program Files (x86)-Zipz.exe" x -y -o"%%~dpI\%%~nI" "%%I"
)
pause
回答by RGuggisberg
Is it possible that some of your zip files have a space in the name? If so your 1st line should be:
您的某些 zip 文件的名称中是否可能有空格?如果是这样,您的第一行应该是:
for /F "usebackq" %%I IN (`dir /b /s "*.zip"`) DO (
Note the use of ` instead of ' See FOR /?
注意使用 ` 而不是 ' 参见 FOR /?