Created
December 24, 2022 20:46
-
-
Save sa7mon/1f6e0ec59ad0da2b672cd70d197440e4 to your computer and use it in GitHub Desktop.
Randomly rename all files in a folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename all files in a folder to a random name, while keeping the original extension | |
$path = "path\to\files\here" | |
foreach($file in $(Get-ChildItem -Path $($path + "*"))) { | |
$extension = [System.IO.Path]::GetExtension($file.FullName); | |
$randomName = [System.IO.Path]::ChangeExtension([System.IO.Path]::GetRandomFileName(), $extension) | |
Write-Host "Changing File $($file.Name) to $randomName" | |
Move-Item -Path $file.FullName -Destination (Join-Path -Path $path -ChildPath $randomName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment