# How to generate MD5 hash value for multiple files in a folder using cmd

CertUtil -hashfile yourFileName MD5
can be used to obtain the MD5 hash value for a particular file.

How can I find the MD5 hash values for multiple files in a folder using cmd?

I know you asked specifically for cmd, but if you're using Windows 8.1 or higher, consider using Powershell instead:

Get-FileHash -Algorithm MD5 -Path (Get-ChildItem "\\path\to\files\*.*" -Recurse)


The Recurse switch is, of course, optional. You can pipe it to Export-Csv to get a list of files and their hashes.

You can use this in Windows 7, but you have to upgrade Powershell to version 4 first.

• Piping results to CSV as | export-csv -Path D:\abc.csv -NoTypeInformation. Aug 10, 2021 at 15:38

You could use the following script:

for %%f in (*) do (
certutil -hashfile "%%f" MD5
)

• Thanks for reminding me about the quotes.   I always remember to use them in Unix, but sometimes I forget about Windows. Sep 11, 2017 at 16:43

The standard way to run a command on multiple files in CMD is the for command.  You can get usage information by typing for /?.  A simple solution for your problem is

for %F in (*) do @certutil -hashfile "%F" MD5


Here %F is a variable.  You can choose any letter — any single letter — for the variable name (use the same name in both places, of course) — and note that it is case-sensitive (%F is not the same as %f).  If you do this in a script, use double percent signs (e.g., %%F).

The quotes around the second appearance of the variable ("%F") (as suggested by nullterminatedstring’s answer) are required if any of the filenames contain spaces.

You can put a list of filenames and/or wildcards between the parentheses; e.g.,

for %F in (file1 file2 a* b*) do …


certutil is somewhat verbose.  You may want to cut down on the chatter by saying

for %F in (*) do @certutil -hashfile "%F" MD5 | find /v "hashfile command completed successfully"


(to filter out the command completed successfully messages).

I calculated the hash of all files on a drive and exported them to a .csv by using this script in PowerShell:

Get-ChildItem C: -Recurse |
Get-FileHash -Algorithm MD5 |
Export-Csv -Path C:\Users\yourname\Documents\Output\hashes.csv -NoTypeInformation
Import-Csv -Path C:\Users\yourname\Documents\Output\hashes.csv


Be sure to have the .csv file created in that location before you run the script. The script won't create the container for you. There's no need to clear the data from the .csv file between runs, it clears itself.

Run this a few times to make sure you get consistent data output. For some reason my first successful .csv output didn't pull all the data. Tested 2-3 more times and got consistent output after that.

You can then Save As your .csv file as an Excel workbook. .csv files open with Excel.

• The term 'Get-FileHash' is not recognized.
– bryc
Nov 14, 2020 at 12:12

I created this scripts for some reason and Hope this script will helps someone too.

@echo off

set count=0

set /p ext="File Extension: "
set /p dest="Directory Path:"
set /p hashtype="Hash Algirthm (MD5,Sha1,Sha256,Sha512): "

:: Robocopy

setlocal ENABLEDELAYEDEXPANSION

for /f "tokens=*" %%a in ('dir !dest!\!ext! /a:-d-l-h /b /s') do (

set file=%%a
for /f "eol=C tokens=* skip=1" %%b in ('certutil -hashfile "!file!" !hashtype!') do (

set /a count += 1

echo !count! - "%%b" "!file!"
echo !count! - "%%b" >> %dest%\hashes.log
echo !count! - "%%b" "!File!" >> %dest%\Files.log
)

)

exit /b