How to generate MD5 hash value for multiple files in a folder using cmd
Solution 1:
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.
Solution 2:
You could use the following script:
for %%f in (*) do (
certutil -hashfile "%%f" MD5
)
Solution 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 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).