[英]Powershell script to get last build directory
I want to create powershell script/command to get the latest build directory name. 我想创建powershell脚本/命令来获取最新的构建目录名称。 Say here are the list of folders i have build_01_01_2018.1 build_01_01_2018.2 build_01_01_2018.3 and so on.... I want to get the latest build number. 说这里是我拥有build_01_01_2018.1 build_01_01_2018.2 build_01_01_2018.3的文件夹列表,依此类推......我想获取最新的内部版本号。
I was able to get it thorugh following. 我可以通过以下方式得到它。 But if any older builds are deleted i wont get exact last build. 但是,如果删除了任何较旧的版本,我将无法获得确切的上一个版本。 Any better approach ? 有更好的方法吗?
$currentTime=$(Get-Date -Format o)
$getDate=$currentTime.split("T")
$getDate = $getDate[0].replace('-','_')
$previousBuildCount= (Get-ChildItem build_2018_08_16.* -Path C:\builds\).Name.count
$buildVersion='build' + '_' + $getDate + '.' + ($previousBuildCount + 1)
You can try simple regex parser: 您可以尝试使用简单的正则表达式解析器:
#demo data
1 | out-file build_01_01_2018.1
2 | out-file build_01_01_2018.2
4 | out-file build_01_01_2018.4
#solution
Get-ChildItem build_01_01_2018.* | % {
[int][Regex]::Match($_.Name, '(?<=build_01_01_2018\.).*').Value
} | Measure -Maximum | select -ExpandProperty Maximum
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.