特定のテキストのテキストファイルを検索して、一致する場合にのみそのテキストを別のテキストファイルに出力しようとしています。私はこれを作るのに苦労している。私が持っているコードを添付しましたが、何がresults.txtファイルを作成していてもファイルは空白です。 multiplatform_201604110718.txtにCCTK STATUS CODE:SUCCESSがある場合、results.txtファイルを作成するだけです。あなたが本当に一つだけのファイルを確認する必要がある場合はPowershellがアウトファイルを発行します
$Path = "C:\multiplatform_201604110718.txt"
$Text = "CCTK STATUS CODE : SUCCESS"
$PathArray = @()
$Results = "C:\results.txt"
# This code snippet gets all the files in $Path that end in “.txt”.
Get-ChildItem $Path -Filter “*.txt” |
Where-Object { $_.Attributes -ne “Directory”} |
ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern $Text) {
$PathArray += $_.FullName
$PathArray += $_.FullName
}
}
Write-Host “Contents of ArrayPath:”
$PathArray | ForEach-Object {$_}
$PathArray | % {$_} | Out-File "C:\Resuts.txt"
あなたの '$ PathArray'が正しくコンソールに出力されていますか? – Matt
これは、テキストファイルに "ArrayPathの内容: C:¥multiplatform_201604110718.txt"のテキストが含まれている場合の出力です。テキストファイルにテキストが含まれていない場合は、出力: "ArrayPathの内容:" – James