삭제를 포함하여 Windows에서 zip 파일을 재귀적으로 추출하려면 어떻게 해야 합니까?

삭제를 포함하여 Windows에서 zip 파일을 재귀적으로 추출하려면 어떻게 해야 합니까?

Windows에서 zip 파일을 어떻게 재귀적으로 추출할 수 있나요? 각 zip 파일은 새 하위 디렉터리에 압축을 풀어야 하며 나중에 zip 파일을 삭제해야 합니다.

기존 또는 생성된 각 디렉터리에서 추가 기존 zip 파일 등을 검색해야 합니다.

그래서 문제는 아마도 더 많은 zip 파일이 있는 많은 디렉토리를 포함하는 거대한 zip 파일이 있다는 것입니다. 원본 zip 파일은 모든 zip 파일에서 해제되어야 하며 원본 디렉터리 트리는 유지되어야 하며 각 zip 파일은 자체 디렉터리로 표시되어야 한다는 규칙이 적용됩니다.

따라서 뒤에 있는 논리는 다음과 같습니다. 디렉터리에서 파일의 압축을 풀고 zip 파일을 삭제합니다. -> 해당 디렉터리로 이동하여 동일한 방식으로 거기에 있는 모든 zip 파일의 압축을 풉니다. -> 디렉터리의 모든 기존 하위 디렉터리로 이동하여 동일한 작업을 수행합니다. -> 등 재귀적으로

재귀적으로 프로그래밍된 배치 스크립트 파일에 대한 대략적인 제안:

unzip_folder(%%directory):

  for %%file (%%directory/*.zip) do (unzip %%file | del %%file)

  for /d %%directory (*) do ( call unzip_folder(%%directory) )

  return

답변1

지금 추출이것을 한다. 보다http://www.extractnow.com/Usage.aspx#process. Chrome 및 다른 브라우저에서는 앱을 악성 코드/스파이웨어로 표시합니다.저자는 이것이 설치 프로그램에서 나온 것이라고 주장합니다.그리고 다음을 가리킨다.휴대용 버전설치 프로그램을 원하지 않는 사람들을 위한 것입니다(Chrome에서는 해당 zip 파일을 악성이라고 부르기도 하지만).

답변2

이것은 당신에게 효과가 있을 것입니다(나에게도 효과가 있습니다). 다른 폴더가 있으면 해당 폴더를 반복하여 가능한 모든 항목의 압축을 푼다는 점에 유의하세요. 내 권장 사항: 실행하기 전에 zip 파일 자체(및 이 배치 파일)를 디렉터리에 넣으세요.

:: 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.

답변3

echo %rant%

자, 여기 있습니다... 몇 시간에 걸친 연구, 실패한 시도 및 많은 조작의 결과입니다(PowerShell을 사용해도 - 기본적으로 긴 파일 경로를 지원하지 않습니다 -쳇!)... 실제로 아카이브를 재귀적으로 추출하여 삭제를 위해 단일 폴더에 모두 넣는 버전...


나는 Pat의 답변을 받아 길이가 260자를 넘는 긴 파일 경로를 지원하기 위해 많은 수정을 했습니다!:

@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

답변4

Andrew의 '''setx PATH "%PATH%;C:\Program Files\7-Zip"'''이 어떤 이유로든 사용되지 않았기 때문에 Pat을 수정했습니다.

@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.

.zip 파일이 있는 경로의 cmd.exe에 있는 동안 "unzipRecursively0.bat /yd"로 실행했습니다.

관련 정보