Skip to content

Instantly share code, notes, and snippets.

@sa7mon
Created December 24, 2022 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sa7mon/1f6e0ec59ad0da2b672cd70d197440e4 to your computer and use it in GitHub Desktop.
Save sa7mon/1f6e0ec59ad0da2b672cd70d197440e4 to your computer and use it in GitHub Desktop.
Randomly rename all files in a folder
# 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