update script to be invoked only in folder where you want to remove version from folders
This commit is contained in:
parent
b449ded8fe
commit
642edffcfe
@ -1,9 +1,10 @@
|
|||||||
# Get each folder in the current directory
|
# Get each folder in the current directory
|
||||||
$folders = Get-ChildItem -Directory
|
$folders = Get-ChildItem -Directory
|
||||||
|
|
||||||
|
# Array of arrays to store work queue
|
||||||
|
$work = @()
|
||||||
|
|
||||||
foreach ($folder in $folders) {
|
foreach ($folder in $folders) {
|
||||||
# Get each folder in the folder
|
|
||||||
$new_folders = Get-ChildItem -Path $folder.FullName -Directory
|
|
||||||
foreach ($folder in $new_folders) {
|
|
||||||
# Find the version number in the folder name
|
# Find the version number in the folder name
|
||||||
$version = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)'
|
$version = $folder.Name -match '(\d+\.\d+\.\d+\.\d+)'
|
||||||
if ($version) {
|
if ($version) {
|
||||||
@ -16,9 +17,10 @@ foreach ($folder in $folders) {
|
|||||||
$new_name = $matches[1]
|
$new_name = $matches[1]
|
||||||
$new_name = $new_name + $matches[2]
|
$new_name = $new_name + $matches[2]
|
||||||
}
|
}
|
||||||
|
$toadd = @($folder.FullName, $new_name)
|
||||||
|
$work += $toadd
|
||||||
|
|
||||||
#Rename-Item -Path $folder.FullName -NewName $new_name
|
Write-Host "Rename $folder to $new_name"
|
||||||
Write-Host "Renamed $folder to $new_name"
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
# Find the version number in the folder name
|
# Find the version number in the folder name
|
||||||
@ -33,9 +35,10 @@ foreach ($folder in $folders) {
|
|||||||
$new_name = $matches[1]
|
$new_name = $matches[1]
|
||||||
$new_name = $new_name + $matches[2]
|
$new_name = $new_name + $matches[2]
|
||||||
}
|
}
|
||||||
|
$toadd = @($folder.FullName, $new_name)
|
||||||
|
$work += $toadd
|
||||||
|
|
||||||
#Rename-Item -Path $folder.FullName -NewName $new_name
|
Write-Host "Rename $folder to $new_name"
|
||||||
Write-Host "Renamed $folder to $new_name"
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
# Find the version number in the folder name
|
# Find the version number in the folder name
|
||||||
@ -50,10 +53,14 @@ foreach ($folder in $folders) {
|
|||||||
$new_name = $matches[1]
|
$new_name = $matches[1]
|
||||||
$new_name = $new_name + $matches[2]
|
$new_name = $new_name + $matches[2]
|
||||||
}
|
}
|
||||||
|
$toadd = @($folder.FullName, $new_name)
|
||||||
|
$work += $toadd
|
||||||
|
|
||||||
#Rename-Item -Path $folder.FullName -NewName $new_name
|
Write-Host "Rename $folder to $new_name"
|
||||||
Write-Host "Renamed $folder to $new_name"
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Read-Host -Prompt "Press Enter to continue"
|
||||||
|
foreach ($item in $work) {
|
||||||
|
Rename-Item -Path $item[0] -NewName $item[1]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user