Last active
January 11, 2024 22:23
-
-
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
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 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