아카이브에 디렉터리 루트 이름을 추가하지 않고 디렉터리에서 여러 아카이브를 생성합니다.

아카이브에 디렉터리 루트 이름을 추가하지 않고 디렉터리에서 여러 아카이브를 생성합니다.

이 일괄 처리는 폴더에 여러 아카이브를 생성하는 데 적합하지만 루트 폴더를 아카이브에 추가합니다. 루트 내부의 파일만 추가하고 싶습니다. 이것은 내가 가지고 있는 코드입니다:

for /d %%X in (*) do "C:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X"

답변1

당신은 단지~을 위한매개변수를 생략하고 반복하면 /dzip 아카이브 파일 생성을 설명하는 것처럼 작동하며 상위 폴더를 포함하지 않습니다.

명령

메모: 그러면 해당 파일만 zip에 있는 디렉터리의 각 파일에 대한 zip 아카이브 파일이 추가됩니다.

for %%X in (*) do "C:\Program Files\7-Zip\7z.exe" a "%%~X.zip" "%%~X"

메모: 이렇게 하면 해당 디렉터리의 모든 파일만 지정한 하나의 zip 파일에 추가됩니다.

for %%X in (*) do "C:\Program Files\7-Zip\7z.exe" a "<MyZipFileName>.zip" "%%~X"

Nest 루프 명령

메모: 이렇게 하면 배치 파일이 있는 디렉터리 아래 디렉터리의 파일만 디렉터리 이름과 일치하는 zip 파일에 추가됩니다.

@ECHO ON

FOR /F "TOKENS=*" %%A in ('DIR /S /B /AD "*"') DO (
  FOR %%B IN (*) DO (
      "C:\Program Files\7-Zip\7z.exe" a "%%~fA.zip" "%%~fA\*")
)
EXIT

추가 리소스

  • /F의 경우
  • FOR /?

        tokens=x,y,m-n  - specifies which tokens from each line are to
                          be passed to the for body for each iteration.
                          This will cause additional variable names to
                          be allocated.  The m-n form is a range,
                          specifying the mth through the nth tokens.  If
                          the last character in the tokens= string is an
                          asterisk, then an additional variable is
                          allocated and receives the remaining text on
                          the line after the last token parsed.
    
  • 디렉토리
  • 을 위한
  • (추가) 명령

관련 정보