要在Windows下计算目录及其子目录下所有文件的MD5值,你可以使用PowerShell脚本来实现。以下是一个示例脚本:
# 导入System.Security.Cryptography命名空间 Add-Type -TypeDefinition @" using System; using System.IO; using System.Security.Cryptography; "@ # 计算文件的MD5哈希值 function Get-FileMD5($filePath) { $md5 = [MD5]::Create() $stream = [System.IO.File]::OpenRead($filePath) $hash = [BitConverter]::ToString($md5.ComputeHash($stream)) $stream.Close() return $hash.Replace("-", "").ToLower() } # 递归计算目录下的所有文件的MD5值 function Get-DirectoryMD5($directoryPath) { $files = Get-ChildItem $directoryPath -File -Recurse $md5Hashes = @() foreach ($file in $files) { $md5Hash = Get-FileMD5 $file.FullName $md5Hashes += "$md5Hash $($file.FullName)" } return $md5Hashes } # 要计算的目录路径 $directoryPath = "C:\Your\Directory\Path" # 获取目录下所有文件的MD5值 $md5Hashes = Get-DirectoryMD5 $directoryPath # 将MD5值保存到文件 $md5Hashes | Out-File -FilePath "C:\MD5Hashes.txt" Write-Host "MD5哈希值已计算并保存到C:\MD5Hashes.txt"