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 に答える