Reputation: 385
I have a text file that contains some text and end of the file "Version"="1.3.0"
I would like to increment the build number "Version"="1.4.0". in the same file, without affecting the other contents.
help needed in powershell please.
Upvotes: 1
Views: 2010
Reputation: 385
Thanks a lot @Matt && @TravisEz13 for your tips. with your help here is the another working version.
$Verfile = "C:\Work\Example\versionfile.reg"
$fileContents = (Get-Content $Verfile | Select -Last 1)
$parts=$fileContents.Split('=')
$versionString = $parts[1].Replace('"','')
$version = [Version]$versionString
$newVersionString = (New-Object -TypeName 'System.Version' -ArgumentList @($version.Major, ($version.Minor+1), $version.Build)).ToString()
(gc $Verfile) -replace "$versionString", "$newVersionString" | sc $Verfile
Upvotes: 1
Reputation: 2413
I assume you can parse the file to the point you get to similar content you give in your question. Additionally, my example is lacking in error handling.
$fileContents = '"Version"="1.4.0"'
$parts=$fileContents.Split('=')
$versionString = $parts[1].Replace('"','')
$version = [Version]$versionString
$newVersionString = (New-Object -TypeName 'System.Version' -ArgumentList @($version.Major, ($version.Minor+1), $version.Build)).ToString()
$fileContents.Replace($versionString,$newVersionString)
"Version"="1.5.0"
Upvotes: 1