Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Created February 26, 2024 22:05
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 Edwardtonnn/1df25891b99f4bae2f63930ac224f62a to your computer and use it in GitHub Desktop.
Save Edwardtonnn/1df25891b99f4bae2f63930ac224f62a to your computer and use it in GitHub Desktop.
rename all images in all folders 01 02 03 etc in
Get-ChildItem -Directory | ForEach-Object {
$Folder = $_
$i = 1
Get-ChildItem $Folder -File | ForEach-Object {
$NewName = "{0:D2}.jpg" -f $i++
# Check if the file is already named correctly
if ($_.Name -ne $NewName) {
$NewPath = Join-Path $Folder.FullName $NewName
# Check if a file with the new name already exists to avoid overwriting
if (-Not (Test-Path $NewPath)) {
Rename-Item $_.FullName -NewName $NewName
} else {
Write-Host "Skipping $_.FullName because $NewPath already exists."
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment