Belirli bir metne ait bir metin dosyasını aramaya çalışıyorum, sonra bu metni yalnızca eşleştiğinde farklı bir metin dosyasına gönderin. Bunu yapmakta zorluk çekiyorum. Sahip olduğum kodu ekledim, ancak sorun ne olursa olsun bir results.txt dosyası oluşturuyor ve dosya boş. Ben sadece multiplatform_201604110718.txt CCTK DURUM KODU: BAŞARISINIZDA ise oluşturulacak results.txt dosyasının olmasını istiyorum. Eğer gerçekten sadece bir dosyayı kontrol gerekiyorsaPowershell, dosya dışına çıkıyor
$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 'konsolunuz doğru şekilde konsol çıkışı veriyor mu? Sadece bu tam olarak '$ PathArray' yazmanız yeterlidir – Matt
Metin dosyası aşağıdakileri içeriyorsa bu çıktı: "ArrayPath İçindekiler: C: \ multiplatform_201604110718.txt" Metin dosyası metin içermiyorsa, çıktı : "ArrayPath İçindekiler:" – James