Skip to content

Instantly share code, notes, and snippets.

@SanSan-
Last active February 27, 2024 11:46
Show Gist options
  • Save SanSan-/751e955a1b1e5d881d873a493fe4f34d to your computer and use it in GitHub Desktop.
Save SanSan-/751e955a1b1e5d881d873a493fe4f34d to your computer and use it in GitHub Desktop.
In current dir rename all img with selected extension to they hash-code
$Algo = "MACTripleDES"
$current = Get-Location
if ($args[0] -ne $null) {
$Ext = $args[0]
} else {
$Ext = ".png"
}
$files = Get-ChildItem -Path $current.Path -Recurse | Where-Object {$_.Extension -eq $Ext}
Write-Output $files
foreach ($file in $files)
{
$fullFileName = $file.FullName
$fileHash = Get-FileHash -Path $fullFileName -Algorithm $Algo
$newHash = $fileHash.Hash
$newFileName = "$newHash$Ext"
Rename-Item -Path $fullFileName -NewName $newFileName
Write-Output "Rename $newFileName complete!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment