我需要从同一个批处理文件中生成的文件列表中生成一个带有 hashfile 标签的文件。这是我到目前为止的代码:
@echo off
setlocal enabledelayedexpansion
:: Set the variables for this script.
set testfolder=c:\test\test folder
set listfile=c:\test\output\file list.txt
set hashfile=c:\test\output\hashes.txt
:: Delete any of the files that were created the last time this script was ran.
del "%hashfile%"
del "%listfile%"
cls
:: Generate a file with a list of all of the files (with path) in designated folder and subdirectories.
:: Directory and subdirectory names are not included in the list. Only files.
dir /s /b /a-d "%testfolder%" > "%listfile%"
:: Assign each line of the file above to its own variable.
set counter=1
for /f "usebackq delims=" %%x in ("%listfile%") do (
set "line_!counter!=%%x"
set /a counter+=1
)
:: Count the number of lines in the above file to use as a reference point.
set /a numlines=counter - 1
:: Generate an MD5 hash for each variable and write it to a file with a blank space between each.
for /l %%x in (1,1,%numlines%) do (
certutil -hashfile "!line_%%x!" MD5 >> "%hashfile%"
echo( >> "%hashfile%"
)
eof
对于我为其生成哈希文件的大多数文件,我得到如下内容:
MD5 hash of file c:\test\test folder\Citrix 2.bmp:
31 34 d6 04 cd b0 4b ef a7 63 c3 e9 ae a8 3d 01
CertUtil: -hashfile command completed successfully.
但有时我会收到如下错误:
CertUtil: -hashfile command FAILED: 0x800703ee (WIN32: 1006)
CertUtil: The volume for a file has been externally altered so that the opened file is no longer valid.
- 为什么有些文件会给出这个错误?
- 如何删除以CertUtil:开头的任何行,这样我就没有不必要的行,或者有没有办法只将 CertUtil 命令的前 2 行写入文件。
- 在
%hashfile%
它的最终形式之后,我想运行certutil -hashfile "%hashfile% MD5
并将哈希码分配给一个变量。它的语法是什么?