简体   繁体   中英

How do I make CertUtil recursively go into my folders and subfolders

Simply put I am trying to take a hash of all of my files in a given directory. I am doing this by calling CertUtil and running:

for %F in (L:\TestDirectory\*) 
do (certutil -hashfile "%F" MD5&echo.) >> L:\certutilOutput.txt

This works well, but only for the current directory as it does not go into my next subfolder: "L:\\TestDirectory\\NetFolder\\ which contains another set of files. I would like this to be able to go down several layers.

I feel like I am missing something very simple, any help is appreciated.

To base this on the original code and put it in the full solution that @dave_thompson_085 referenced, save the following as a bat file:

@echo off
for /R "L:\TestDirectory" %%f in (*) do ( 
  certutil -hashfile "%%f" MD5
)>>L:\certutilOutput.txt

Brilliant minds work alike. What are the odds that, after 3+ years of sitting unanswered, two of us would be working on answers to this question at the same time?

My variation features (1) the optional use of FIND to eliminate potentially unwanted clutter from the output and (2) a check to remove a preexisting output file:

@echo off
if exist "L:\certutilOutput.txt" del "L:\certutilOutput.txt"
for /r "L:\TestDirectory" %%F in (*) do certutil -hashfile "%%F" MD5 | find /i /v "certutil:" >> "L:\certutilOutput.txt"

Sadly, it still doesn't put both the filename and the hash on one line, which is what I've been seeking .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM