1

我有一个文本文件来存储我的测试名称。测试名称之后有时会有一个包含 14 位时间戳的日期。测试名称可以是:

data-c(festo1-small1);divider-bin-1.4.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(festo1)-win1

或者

data-c(festo1-small1);divider-bin-1.4.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(festo1)-win1_20130620123306

我想重用这个文件/测试名。如果已经有时间戳,我需要去掉时间戳,然后添加当前时间戳。这是我到目前为止得到的:

#rescue testname for another run                                                                                                                                                                                                           
$testname = Get-Content "output\testname"

Write-Host Old: $testname

#strip date from testname                                                                                                                                                                                                                  
$testname = $testname.Substring(0,$string.Length - 14)
$olddate = $testname.Substring($string.Length - 14)

Write-Host OldDate: $olddate

#add new Date                                                                                                                                                                                                                              
$startTime = Get-Date -format yyyyMMddHHmmss
$testname += "_"
$testname += $startTime

Write-Host New: $testname

如何检查是否有时间戳/最后 14 个字符是否为数字?如何从字符串中剪切测试名称?

4

1 回答 1

2

这个?

$filename = "data-c(festo1-small1);divider-bin-1.4.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(festo1)-win1_20130620123306"

$filename  -replace '\d{14}$'
于 2013-06-20T17:03:35.307 回答