Compare commits

..

No commits in common. "d3648342e5e5fb4c54d988b31f3c54fead034323" and "b449ded8fed3da1a095014b2bf6f055a400cca3a" have entirely different histories.

View File

@ -1,72 +1,59 @@
# Get each folder in the current directory # Get each folder in the current directory
$folders = Get-ChildItem -Directory $folders = Get-ChildItem -Directory
# Array to store the folders that need to be renamed
$work = @()
foreach ($folder in $folders) { foreach ($folder in $folders) {
# Find the version number in the folder name # Get each folder in the folder
$version = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)' $new_folders = Get-ChildItem -Path $folder.FullName -Directory
if ($version) { foreach ($folder in $new_folders) {
# Replace entire folder name with the version number # Find the version number in the folder name
$new_name = $matches[0] $version = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)'
if ($version) {
# Replace entire folder name with the version number
$new_name = $matches[0]
# if version has a alpha character, remove it, eg 0.1.0a, then re-add it to new name # if version has a alpha character, remove it, eg 0.1.0a, then re-add it to new name
$alpha = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)([a-zA-Z])' $alpha = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)([a-zA-Z])'
if ($alpha) { if ($alpha) {
$new_name = $matches[1] $new_name = $matches[1]
$new_name = $new_name + $matches[2] $new_name = $new_name + $matches[2]
}
#Rename-Item -Path $folder.FullName -NewName $new_name
Write-Host "Renamed $folder to $new_name"
continue
} }
$toadd = New-Object PSObject # Find the version number in the folder name
$toadd | Add-Member -MemberType NoteProperty -Name path -Value $folder.FullName $version = $folder.Name -match '(\d+\.\d+\.\d+)'
$toadd | Add-Member -MemberType NoteProperty -Name newname -Value $new_name if ($version) {
$work += $toadd # Replace entire folder name with the version number
$new_name = $matches[0]
Write-Host "Rename $folder to $new_name" # if version has a alpha character, remove it, eg 0.1.0a, then re-add it to new name
continue $alpha = $folder.Name -match '(\d+\.\d+\.\d+)([a-zA-Z])'
} if ($alpha) {
# Find the version number in the folder name $new_name = $matches[1]
$version = $folder.Name -match '(\d+\.\d+\.\d+)' $new_name = $new_name + $matches[2]
if ($version) { }
# Replace entire folder name with the version number
$new_name = $matches[0]
# if version has a alpha character, remove it, eg 0.1.0a, then re-add it to new name #Rename-Item -Path $folder.FullName -NewName $new_name
$alpha = $folder.Name -match '(\d+\.\d+\.\d+)([a-zA-Z])' Write-Host "Renamed $folder to $new_name"
if ($alpha) { continue
$new_name = $matches[1]
$new_name = $new_name + $matches[2]
} }
$toadd = New-Object PSObject # Find the version number in the folder name
$toadd | Add-Member -MemberType NoteProperty -Name path -Value $folder.FullName $version = $folder.Name -match '(\d+\.\d+)'
$toadd | Add-Member -MemberType NoteProperty -Name newname -Value $new_name if ($version) {
$work += $toadd # Replace entire folder name with the version number
$new_name = $matches[0]
Write-Host "Rename $folder to $new_name" # if version has a alpha character, remove it, eg 0.1.0a, then re-add it to new name
continue $alpha = $folder.Name -match '(\d+\.\d+)([a-zA-Z])'
} if ($alpha) {
# Find the version number in the folder name $new_name = $matches[1]
$version = $folder.Name -match '(\d+\.\d+)' $new_name = $new_name + $matches[2]
if ($version) { }
# Replace entire folder name with the version number
$new_name = $matches[0]
# if version has a alpha character, remove it, eg 0.1.0a, then re-add it to new name #Rename-Item -Path $folder.FullName -NewName $new_name
$alpha = $folder.Name -match '(\d+\.\d+)([a-zA-Z])' Write-Host "Renamed $folder to $new_name"
if ($alpha) { continue
$new_name = $matches[1]
$new_name = $new_name + $matches[2]
} }
$toadd = New-Object PSObject
$toadd | Add-Member -MemberType NoteProperty -Name path -Value $folder.FullName
$toadd | Add-Member -MemberType NoteProperty -Name newname -Value $new_name
$work += $toadd
Write-Host "Rename $folder to $new_name"
continue
} }
} }
Read-Host -Prompt "Press Enter to continue"
foreach ($item in $work) {
Rename-Item -Path $item.path -NewName $item.newname
}