5

As mentioned in this page, the command:

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?

5

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. – G-Man Says 'Reinstate Monica' Sep 11 '17 at 16:43
3

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 an 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).

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.