
외부 파일 PathList.txt에 있는 하위 폴더에 있는 모든 파일의 MD5 값을 가져오려고 합니다.
스크립트에서 정의된 경로 이름을 사용하도록 할 수 없습니다 %%i
.
"C:\Temp\example\"
대신 사용한 예에서는 %%i
스크립트가 작동합니다.
@ECHO off
echo Files MD5 > MD5_log.txt
FOR /F %%i IN (PathList.txt) DO (
@FOR /R "C:\Temp\example\" %%G in (*) DO (
for %%a in (%%G) do certutil -hashfile "%%~a" MD5 | find /i /v "certutil">> MD5_log.txt
)
)
경로목록.txt
C:\folder1\
C:\folder2\
이것은 오래된 컴퓨터용이며 Powershell 옵션이 없습니다.
어떻게 작동하게 할 수 있나요?
답변1
스크립트가 다음에 정의된 경로 이름을 사용하도록 할 수 없습니다.%%i
아래에서 작업 배치 파일(test.cmd)을 찾으십시오.
@echo off
setlocal EnableDelayedExpansion
echo Files MD5 > MD5_log.txt
for /f "tokens=*" %%i in (PathList.txt) do (
for /f "tokens=*" %%j in ('dir /b /s "%%i"') do (
certutil -hashfile "%%j" MD5 | find /i /v "certutil" >> MD5_log.txt
)
)
endlocal
샘플 출력:
> type PathList.txt
f:\test\bar
f:\test\bar - Copy
f:\test\foo
> test
> type MD5_log.txt
Files MD5
MD5 hash of file f:\test\bar\test.cmd:
eb 4f 28 f4 a0 b0 c5 21 0d e8 5f 99 0f d8 fd ab
MD5 hash of file f:\test\bar\test.html:
3a 68 3a f6 4e 88 f1 22 62 d6 46 dc bb 54 59 45
MD5 hash of file f:\test\bar\test.ps1:
07 fd 41 59 6b fa 90 06 49 4f bf e3 dd be 0d 1c
MD5 hash of file f:\test\bar - Copy\test with space.cmd:
eb 4f 28 f4 a0 b0 c5 21 0d e8 5f 99 0f d8 fd ab
MD5 hash of file f:\test\bar - Copy\test.html:
3a 68 3a f6 4e 88 f1 22 62 d6 46 dc bb 54 59 45
MD5 hash of file f:\test\bar - Copy\test.ps1:
07 fd 41 59 6b fa 90 06 49 4f bf e3 dd be 0d 1c
MD5 hash of file f:\test\foo\test.sh:
d2 12 38 76 9d 8e 9f 51 1a 60 0b 15 6c 0c f8 38
MD5 hash of file f:\test\foo\test.xml:
cd 8f d1 c6 66 ac ff 7f 98 d2 e9 4a ad b5 20 1f
MD5 hash of file f:\test\foo\test.yaml:
78 ce a1 f0 97 46 ee 32 c6 7f f6 16 8d 94 04 d2
MD5 hash of file f:\test\foo\test.yml:
78 ce a1 f0 97 46 ee 32 c6 7f f6 16 8d 94 04 d2