0

当社の製品は、一部のデータを CSV ファイルに記録する複数の WCF サービスで構成されています。各サービスは、シーケンス番号を使用して名前が付けられた独自のファイル セットに書き込みます。例えば:

Product.ServiceA1.csv
Product.ServiceA2.csv
Product.ServiceA3.csv
Product.ServiceB1.csv
Product.ServiceB2.csv
Product.ServiceB3.csv

ファイルはすべて共通のフォルダーに書き込まれますD:\Product\log

各サービスのすべてのファイルを処理するスクリプトを作成しており、次のようにサービス名で結果を識別したいと考えています。

ServiceA: 25
ServiceB: 30

個別のサービス名のリストを取得するために、次の PowerShell コードを思いつきましたが、もっと良い方法があるかどうか疑問に思っていました。

# Get a list of all the file names; remove the 'Product' prefix and CSV file
# extension so we get just the base name.
$services = get-childitem $logFiles -Name | foreach { $_.Split(".")[1]}

# Remove all the sequence numbers and get a list of the unique names.
$services = [regex]::replace($services,'\d{1,3}','').split(" ") | get-unique

ありがとう :)

4

1 に答える 1

1

正規表現で「オールインワン」を試すことができます。

$services = (Get-Childitem -Path $logFiles -Name) -replace '(?:.+?)([^\.0-9]+)(?:\d+)(?:\.csv)', '$1' | Get-Unique
于 2013-02-22T16:09:26.627 に答える