我想解压缩特定目录中的所有文件,并在解压缩时保留文件夹名称。
以下批处理脚本并没有完全实现这一功能。它只是将一堆文件丢在那里,而没有将它们放入文件夹中,甚至无法完成任务。
这里出了什么问题?
for /F %%I IN ('dir /b /s *.zip') DO (
"C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI" "%%I"
)
我想解压缩特定目录中的所有文件,并在解压缩时保留文件夹名称。
以下批处理脚本并没有完全实现这一功能。它只是将一堆文件丢在那里,而没有将它们放入文件夹中,甚至无法完成任务。
这里出了什么问题?
for /F %%I IN ('dir /b /s *.zip') DO (
"C:\Program Files (x86)\7-Zip\7z.exe" x -y -o"%%~dpI" "%%I"
)
试试这个:
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"
)
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"
)
@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
你的一些压缩文件名中是否含有空格?如果是,你的第一行应该是:
for /F "usebackq" %%I IN (`dir /b /s "*.zip"`) DO (
#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
}
dir /b /s "*.zip"
) DO ( - RGuggisbergfor /F "delims=" %%I IN ('dir /b /s/a-d *.zip') DO (
。 - Endoro