
Wie kann ich Zip-Dateien unter Windows rekursiv entpacken? Jede Zip-Datei muss in ein neues Unterverzeichnis entpackt und anschließend gelöscht werden.
Jedes vorhandene oder erstellte Verzeichnis sollte nach weiteren vorhandenen ZIP-Dateien usw. durchsucht werden.
Das Problem ist also, dass ich eine riesige Zip-Datei habe, die viele Verzeichnisse mit möglicherweise vielen weiteren Zip-Dateien enthält. Die ursprünglichen Zip-Dateien sollten einfach von allen Zip-Dateien befreit werden, der ursprüngliche Verzeichnisbaum sollte erhalten bleiben, mit der Konvention, dass jede Zip-Datei als eigenes Verzeichnis dargestellt werden sollte.
Die Logik dahinter ist also: Datei in einem Verzeichnis entpacken und Zip-Datei löschen -> in dieses Verzeichnis gehen und alle Zip-Dateien dort auf die gleiche Weise entpacken -> in jedes vorhandene Unterverzeichnis des Verzeichnisses gehen und dasselbe tun -> und so weiter rekursiv
Grober Vorschlag für eine rekursiv programmierte Batch-Skriptdatei:
unzip_folder(%%directory):
for %%file (%%directory/*.zip) do (unzip %%file | del %%file)
for /d %%directory (*) do ( call unzip_folder(%%directory) )
return
Antwort1
Jetzt extrahierentut dies. Siehehttp://www.extractnow.com/Usage.aspx#process. Beachten Sie, dass Chrome und möglicherweise auch andere Browser die App als Malware/Spyware kennzeichnen.Der Autor behauptet, dass dies nur vom Installer kommtund verweist auf einetragbare Versionfür diejenigen, die das Installationsprogramm nicht möchten (obwohl Chrome diese ZIP-Datei auch als bösartig bezeichnet).
Antwort2
Das sollte bei Ihnen funktionieren (bei mir funktioniert es). Beachten Sie jedoch, dass, wenn andere Ordner vorhanden sind, diese rekursiv durchsucht werden und alles Mögliche entpackt wird. Meine Empfehlung: Legen Sie Ihre Zip-Datei (und diese Batch-Datei) vor dem Ausführen in ein eigenes Verzeichnis.
:: To actually include the path expansion character (tilde), I had to give valid numbers; see http://ss64.com/nt/rem.html for bug reference. Also, try call /? for more info.
@REM The %~n0 extracts the name sans extension to use as output folder. If you need full paths, use "%~dpn0". The -y forces overwriting by saying yes to everything. Or use -aoa to overwrite.
@REM Using `x` instead of `e` maintains dir structure (usually what we want)
:: If you want recursive, use FOR /R
@FOR /R %%a IN (*.zip) DO @(
@if [%1] EQU [/y] (
@7z x "%%a" -o"%%~dpna" -aoa
) else if [%1] EQU [/yd] (
@7z x "%%a" -o"%%~dpna" -aoa
@if errorlevel 1 (
@echo There was an error so I won't delete
) else (
REM You can also prompt with del /p
@del "%%a"
)
) else (
@echo 7z x "%%a" -o"%%~dpna" -aoa
)
)
@echo USAGE: Use /y to actually do the extraction. Use /yd to extract then delete the zip file.
Antwort3
echo %rant%
Also, los geht’s … das Ergebnis stundenlanger Recherche, fehlgeschlagener Versuche und viel Herumprobieren (habe sogar PowerShell ausprobiert – unterstützt standardmäßig keine langen Dateipfade –meine Güte!) ... eine Version, die Archive tatsächlich rekursiv extrahiert und sie alle zum Löschen in einem einzigen Ordner ablegt ...
Ich habe die Antwort von Pat übernommen und sie eingehend überarbeitet, um lange Dateipfade mit mehr als 260 Zeichen zu unterstützen:
@echo off
setlocal enabledelayedexpansion enableextensions
set scriptDir=%~dp0
REM Clear the log files.
echo . > unzipLog.txt
echo . > unzipErrors.txt
mkdir DeleteMe >> unzipLog.txt 2>nul
REM Recurse through all common compressed archive files.
FOR /R %%a IN (*.zip,*.7z,*.rar,*.tar,*.gz) DO (
@echo: >> unzipLog.txt 2>> unzipErrors.txt
@echo: >> unzipLog.txt 2>> unzipErrors.txt
@echo: >> unzipLog.txt 2>> unzipErrors.txt
@echo: >> unzipLog.txt 2>> unzipErrors.txt
@echo: >> unzipLog.txt 2>> unzipErrors.txt
REM Prepend \\?\ to the beginning of each path to handle paths longer than 260 characters.
if [%1] EQU [/y] (
REM Extract only.
7z x "\\?\%%a" -o"%%~dpna" -aoa >> unzipLog.txt 2>> unzipErrors.txt
) else if [%1] EQU [/yd] (
REM Extract and delete.
for %%b in ("%%a") do (
set p=%%~dpb
set f=%%~nxb
)
IF !p:~-1!==\ SET p=!p:~0,-1!
echo "!p!" "!scriptDir!DeleteMe" "!f!"
echo "!p!" "!scriptDir!DeleteMe" "!f!" >> unzipLog.txt 2>> unzipErrors.txt
7z x "\\?\%%a" -o"%%~dpna" -aoa >> unzipLog.txt 2>> unzipErrors.txt
if errorlevel 1 (
echo There was an error so I won't delete >> unzipLog.txt 2>> unzipErrors.txt
) else (
robocopy "!p!" "!scriptDir!DeleteMe" "!f!" /MOVE /FP /NS /NC /NFL /NDL /NP /IS /IT /SL >> unzipLog.txt 2>> unzipErrors.txt
)
) else (
REM Just echo.
echo 7z x "\\?\%%a" -o"%%~dpna" -aoa >> unzipLog.txt 2>> unzipErrors.txt
)
)
REM Can comment this out if you just want to extract the archives to a folder and not delete them...:
REM WARNING: recommended call this manually and very carefully!!!
REM rmdir /S /Q DeleteMe
REM WARNING: recommended call this manually and very carefully!!!
echo Use /y to actually do the extraction. Use /yd to extract then delete the zip file.
echo See unzipLog.txt and unzipErrors.txt!
endlocal
Antwort4
Geänderte Pat's, da Andrew's '''setx PATH "%PATH%;C:\Program Files\7-Zip"''' aus irgendeinem Grund nicht funktionierte:
@FOR /R %%a IN (*.zip) DO @(
@if [%1] EQU [/y] (
@"C:\Program Files\7-Zip\7z.exe" x "%%a" -o"%%~dpna" -aoa
) else if [%1] EQU [/yd] (
@"C:\Program Files\7-Zip\7z.exe" x "%%a" -o"%%~dpna" -aoa
@if errorlevel 1 (
@echo There was an error so I won't delete
) else (
REM You can also prompt with del /p
@del "%%a"
)
) else (
@echo "C:\Program Files\7-Zip\7z.exe" x "%%a" -o"%%~dpna" -aoa
)
)
@echo USAGE: Use /y to actually do the extraction. Use /yd to extract then delete the zip file.
Während Sie sich in cmd.exe im Pfad mit der ZIP-Datei befanden, führten Sie es mit „unzipRecursively0.bat /yd“ aus.