this is my first stack question so go easy on me.
Currently working on a project to create a new folder on a network drive by incrementing off of the previous folders version number.
For example:
5.2.0.0110
-> 5.2.0.0111
Here is my current powershell solution that does the trick:
$SourceFolder = "\\corpfs1\setup\ProtectionSuite\Version 5.2.0.x\5.2.0.0001"
$DestinationFolder = "\\corpfs1\setup\ProtectionSuite\Version 5.2.0.x"
$msiSourceFolder = "\\SourceMsiPath"
$exeSourceFolder = "\\SourceExePath"
if (Test-Path $SourceFolder)
{
$latest = Get-ChildItem -Path $DestinationFolder| Sort-Object Name -Descending | Select-Object -First 1
#split the latest filename, increment the number, then re-assemble new filename:
$newFolderName = $latest.BaseName.Split('.')[0] + "." + $latest.BaseName.Split('.')[1] + "."+ $latest.BaseName.Split('.')[2] + "." + ([int]$latest.BaseName.Split('.')[3] + 1).ToString().PadLeft(4,"0")
New-Item -Path $DestinationFolder"\"$newFolderName -ItemType Directory
Copy-Item $msiSourceFolder -Destination $DestinationFolder"\"$newFolderName
Copy-Item $exeSourceFolder -Destination $DestinationFolder"\"$newFolderName
}
However, one thing that this does not account for is version numbers with string at the end. This solution attempts to covert the string -> int which fails. Some of the folders have strings as they are for internal releases so there is no way to just change my naming semantics.
For example: 5.2.0.1234 (eng)
-> 5.2.0.1235
I would like to ignore any text after the last four digits and increment as shown in the example above. If anyone has a suggestion I am all ears! Thank you.