Created
February 26, 2024 22:05
-
-
Save Edwardtonnn/1df25891b99f4bae2f63930ac224f62a to your computer and use it in GitHub Desktop.
rename all images in all folders 01 02 03 etc in
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
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