2024-05-25 21:05:18 -03:00
|
|
|
# Get each folder in the current directory
|
|
|
|
$folders = Get-ChildItem -Directory
|
2024-05-25 21:11:34 -03:00
|
|
|
|
2024-05-25 21:27:29 -03:00
|
|
|
# Array to store the folders that need to be renamed
|
2024-05-25 21:11:34 -03:00
|
|
|
$work = @()
|
|
|
|
|
2024-05-25 21:05:18 -03:00
|
|
|
foreach ($folder in $folders) {
|
2024-05-25 21:11:34 -03:00
|
|
|
# Find the version number in the folder name
|
|
|
|
$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
|
|
|
|
$alpha = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)([a-zA-Z])'
|
|
|
|
if ($alpha) {
|
|
|
|
$new_name = $matches[1]
|
|
|
|
$new_name = $new_name + $matches[2]
|
2024-05-25 21:05:18 -03:00
|
|
|
}
|
2024-05-25 21:27:29 -03:00
|
|
|
$toadd = New-Object PSObject
|
|
|
|
$toadd | Add-Member -MemberType NoteProperty -Name path -Value $folder.FullName
|
|
|
|
$toadd | Add-Member -MemberType NoteProperty -Name newname -Value $new_name
|
2024-05-25 21:11:34 -03:00
|
|
|
$work += $toadd
|
|
|
|
|
|
|
|
Write-Host "Rename $folder to $new_name"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
# Find the version number in the folder name
|
|
|
|
$version = $folder.Name -match '(\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
|
|
|
|
$alpha = $folder.Name -match '(\d+\.\d+\.\d+)([a-zA-Z])'
|
|
|
|
if ($alpha) {
|
|
|
|
$new_name = $matches[1]
|
|
|
|
$new_name = $new_name + $matches[2]
|
2024-05-25 21:05:18 -03:00
|
|
|
}
|
2024-05-25 21:27:29 -03:00
|
|
|
$toadd = New-Object PSObject
|
|
|
|
$toadd | Add-Member -MemberType NoteProperty -Name path -Value $folder.FullName
|
|
|
|
$toadd | Add-Member -MemberType NoteProperty -Name newname -Value $new_name
|
2024-05-25 21:11:34 -03:00
|
|
|
$work += $toadd
|
|
|
|
|
|
|
|
Write-Host "Rename $folder to $new_name"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
# Find the version number in the folder name
|
|
|
|
$version = $folder.Name -match '(\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
|
|
|
|
$alpha = $folder.Name -match '(\d+\.\d+)([a-zA-Z])'
|
|
|
|
if ($alpha) {
|
|
|
|
$new_name = $matches[1]
|
|
|
|
$new_name = $new_name + $matches[2]
|
2024-05-25 21:05:18 -03:00
|
|
|
}
|
2024-05-25 21:27:29 -03:00
|
|
|
$toadd = New-Object PSObject
|
|
|
|
$toadd | Add-Member -MemberType NoteProperty -Name path -Value $folder.FullName
|
|
|
|
$toadd | Add-Member -MemberType NoteProperty -Name newname -Value $new_name
|
2024-05-25 21:11:34 -03:00
|
|
|
$work += $toadd
|
|
|
|
|
|
|
|
Write-Host "Rename $folder to $new_name"
|
|
|
|
continue
|
2024-05-25 21:05:18 -03:00
|
|
|
}
|
2024-05-25 21:11:34 -03:00
|
|
|
}
|
|
|
|
Read-Host -Prompt "Press Enter to continue"
|
|
|
|
foreach ($item in $work) {
|
2024-05-25 21:27:29 -03:00
|
|
|
Rename-Item -Path $item.path -NewName $item.newname
|
2024-05-25 21:05:18 -03:00
|
|
|
}
|