Windows批处理脚本解压目录中的文件

flvtvl50  于 7个月前  发布在  Windows
关注(0)|答案(5)|浏览(77)

我想解压缩在某个目录下的所有文件,并在解压缩时保留文件夹名称。
下面的批处理脚本并没有完全做到这一点,它只是抛出了一堆文件,而没有把它们放到一个文件夹中,甚至没有完成。
怎么了?

for /F %%I IN ('dir /b /s *.zip') DO (

    "C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI" "%%I" 
)

字符串

nwsw7zdq

nwsw7zdq1#

试试这个:

for /R "C:\root\folder" %%I in ("*.zip") do (
  "%ProgramFiles(x86)%\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI" 
)

字符串
或者(如果您想将文件解压缩到以Zip文件命名的文件夹中):

for /R "C:\root\folder" %%I in ("*.zip") do (
  "%ProgramFiles(x86)%\7-Zip\7z.exe" x -y -o"%%~dpnI" "%%~fI" 
)

gt0wga4j

gt0wga4j2#

Ansgar上面的回应对我来说非常完美,但我也想在提取成功后删除存档。我发现了这个并将其纳入上述内容以给予:

for /R "Destination_Folder" %%I in ("*.zip") do (
  "%ProgramFiles%\7-Zip\7z.exe" x -y -aos -o"%%~dpI" "%%~fI"
  "if errorlevel 1 goto :error"
    del "%%~fI"
  ":error"
)

字符串

bvk5enib

bvk5enib3#

试试这个.

@echo off
for /F "delims=" %%I IN (' dir /b /s /a-d *.zip ') DO (
    "C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI\%%~nI" "%%I" 
)
pause

字符串

zhte4eai

zhte4eai4#

有没有可能你的zip文件的名字中有空格?如果是这样,你的第一行应该是:

for /F "usebackq" %%I IN (`dir /b /s "*.zip"`) DO (

字符串
注意` instead of '的用法见FOR /?

uemypmqf

uemypmqf5#

作为PowerShell脚本(没有第三方工具),您可以运行:

#get the list of zip files from the current directory
$dir = dir *.zip
#go through each zip file in the directory variable
foreach($item in $dir)
  {
    Expand-Archive -Path $item -DestinationPath ($item -replace '.zip','') -Force
  }

字符串
取自用户'pestell159'发布的Microsoft论坛。

相关问题