Skip to content

Instantly share code, notes, and snippets.

@Edwardtonnn
Last active January 11, 2024 22:23
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/0998bbf8d39b4278cbaf13f951540032 to your computer and use it in GitHub Desktop.
Save Edwardtonnn/0998bbf8d39b4278cbaf13f951540032 to your computer and use it in GitHub Desktop.
Reverses dir folder names. Used for gallery reversals. Paste into powershell and hit enter
# Get the list of directories in the current folder
$directories = Get-ChildItem -Directory | Sort-Object Name
# Temporary name for renaming
$tempName = "tempDir"
# Rename directories to temporary names in reverse order
for ($i = 0; $i -lt $directories.Count; $i++) {
$newName = "{0:D2}" -f ($directories.Count - $i)
Rename-Item $directories[$i].Name $tempName$newName
}
# Rename temporary directories to final names
Get-ChildItem -Directory | Where-Object { $_.Name -like "$tempName*" } | ForEach-Object {
$finalName = $_.Name -replace $tempName, ""
Rename-Item $_.Name $finalName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment