certutil -hashfile:处理拖放文件夹中的多个文件

时间:2017-07-27 10:26:35

标签: batch-file for-loop md5 certutil

我正在尝试创建一个批处理脚本,该脚本在文件夹中的每个文件上运行certutil -hashfile MD5,并将输出写入文件。

我在下面有这个代码,除了它只适用于当前文件夹中的文件, 我希望它可以工作,当文件夹被拖放到批处理文件.bat时它只处理该文件夹。

for %%a in (*) do certutil -hashfile %%a MD5 >> MD5_log.txt

还有办法让它在certutil输出文本的迭代之间输出日志文件中的空格吗?

2 个答案:

答案 0 :(得分:0)

实际上非常简单!

只需将(*)更改为("%~1\*")或其他命令行参数即可。如果您有多个拖放文件夹,请执行"%~1\*" "%~2\*"等操作。使用引号(")可以防止出现空间问题。所以路径现在被引用。并且%%a变为%%~a,这意味着要取消引用。

或者,您可以设置包含所有路径的变量并逐个处理它们。

结果:

for %%a in ("%1\*") do certutil -hashfile "%%~a" MD5 >> MD5_log.txt

答案 1 :(得分:-1)

将以下文件存储为.bat文件,并根据需要更改testfolder和outputfile。

@ECHO OFF

setlocal enabledelayedexpansion

:: Set the variables for this script.
set testfolder=C:\Test\
set outputfile=md5_files.txt

cd %testfolder%

echo > %outputfile%

for %%f in (".\*.*") do (
   certutil -hashfile %%f SHA1 >>%outputfile%
   echo %%ff
)



PAUSE