I have a function in Powershell which given a path to a folder, returns a computed hash. I need it to work within a Python script. My question is: how can I convert it to work within Python? Thanks.
function Get-FolderHash ($folder) {
dir $folder -Recurse | ?{!$_.psiscontainer} | %{[Byte[]]$contents += [System.IO.File]::ReadAllBytes($_.fullname)}
$hasher = [System.Security.Cryptography.SHA1]::Create()
$a = [string]::Join("",$($hasher.ComputeHash($contents) | %{"{0:x2}" -f $_}))
Write-Host $a
}
Get-FolderHash "PATH_TO_FOLDER"