1

I'm trying to create a batch script that runs certutil -hashfile MD5 on each file in a folder and write the output to a file.

I have this code below except it only works on the files in the current folder, I would like it to work such that when a folder is drag-dropped into the batch file .bat it processes that folder only.

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

Also is there a way to get it to output spaces in the log file between iterations of the certutil output text?

furutsun
  • 11
  • 1
  • 3

2 Answers2

1

It is actually very simple!


Simply change (*) to ("%~1\*") or other command-line arguments. If you have multiple drag-drop folders, do "%~1\*" "%~2\*", etc. Using quotes (") can prevent issue with space. So paths are now quoted. And %%a becomes %%~a, which means to de-quote.

Alternatively, you can set a variable containing all paths and process them one by one.

Result:

for %%a in ("%1\*") do certutil -hashfile "%%~a" MD5 >> MD5_log.txt
aschipfl
  • 33,626
  • 12
  • 54
  • 99
-1

Store following file as .bat file and change testfolder and outputfile as desired.

@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
  • This doesn't solve in any way the question. The question is about drag&drop a folder on the batch file – jeb Jan 24 '20 at 09:53