I've made a Windows batch script with similar functionality. It uses the CertUtil command-line program that is included with Windows (at least Win7 and later). The lines containing
pause are necessary in order to prevent the window from closing if you're using drag-and-drop. Unfortunately, this means that you'll need to press a key to terminate the script if you run it from the command prompt and redirect the output (e.g., to a file).
Download hash_dir.batLanguage: batch
@echo off
setlocal enableextensions
if [%1]==[] goto synerr
if not exist %1 goto nofile
call :isdir %~a1
if [%_is_dir%]==[F] call :procfile "%~f1"
if [%_is_dir%]==[T] call :procdir "%~f1"
goto:eof
:synerr
echo.
echo Calculates MD5 hash for the input file(s) using Windows's CertUtil command.
echo.
echo USAGE: %~nx0 ^<input^>
echo ^<input^> File or directory for which to generate hashes. If directory,
echo processes all contained files and subdirectories.
echo.
goto:eof
:nofile
echo.
echo ERROR: %1 does not exist.
goto:eof
:isdir
set _is_dir=
set _attr=%1
if [%_attr:~0,1%]==[d] (
set _is_dir=T
) else (
set _is_dir=F
)
goto:eof
:procfile
set _hash=
set _fname="%~f1"
set _fname=%_fname:^^=^%
for /f "delims=" %%A in ('CertUtil -hashfile %_fname% MD5 ^| find /i /v "md5" ^| find /i /v "certutil"') do set "_hash=%%A"
echo %_hash: =% %_fname%
if [%_is_dir%]==[F] pause
goto:eof
:procdir
for /f "delims=" %%A in ('dir /a-d /b /s "%~f1"') do call :procfile "%%~fA"
pause
goto:eof