2017-12-17 1 views
0

처리, 제외, 복사 및 결합하려고하는 텍스트 파일의 디렉터리가 있습니다. 마지막 날의 모든 텍스트 파일을 텍스트 파일의 고유 한 문자열을 기반으로 텍스트 파일을 제외하고 임시 폴더로 복사하려고합니다. 필자는 텍스트 파일을 제외하고 올바른 텍스트 파일을 임시 디렉토리에 복사하는 좋은 방법을 생각해 낼 수 없습니다. 텍스트 파일 처리 디렉터리

$excludematch = "unique: string","unique: string2" 

    foreach ($i in Get-ChildItem $dir\*.txt) { 
      if ($i.CreationTime -gt ($(Get-Date).AddHours(-24))) { 
       if (Get-Content $i.FullName | Select-String -Pattern $stringmatch){ ...do something with matched files... }}} 
#combine all text files in the temp folder into a text file named for that day 
Get-Content -path $temp_copy\*.txt | Set-Content -path $output\$(get-date -f MM-dd-yyyy).txt 

내가 제외 할 파일의 목록을 얻으려면 무슨 생각의 일종이다. 파일을 삭제하고 싶지는 않지만 결합 된 텍스트 파일에 삽입하고 싶지는 않습니다.

미리 감사드립니다.

+0

문제를 작은 부분으로 나누고 정확한 문제에 대해 질문하십시오. –

답변

0

직접 하루에 하나 개의 파일에 파일이 txt 필터링을 전달하려는 경우이 같은 그것을 할 수 :

$excludematch = "unique: string","unique: string2" 

foreach ($i in Get-ChildItem $dir\*.txt) { 
    if ($i.CreationTime -gt ($(Get-Date).AddHours(-24))) { 
    if (!(Get-Content $i.FullName | Select-String -Pattern $excludematch)){ 
     Get-Content $i.FullName | Out-File -Append -FilePath ".\$(get-date -f MM-dd-yyyy).txt" 
    }}} 

당신이 추가 단계를하고 별도로 필터링 된 모든 파일을 넣어하려는 경우 폴더에서 최종 .txt 파일을 만들려면 다음과 같이하십시오.

$excludematch = "unique: string","unique: string2" 

foreach ($i in Get-ChildItem $dir\*.txt) { 
    if ($i.CreationTime -gt ($(Get-Date).AddHours(-24))) { 
    if (!(Get-Content $i.FullName | Select-String -Pattern $excludematch)){ 
     Copy-Item $i -Destination $tmpPath 
    }}} 
foreach ($item in Get-ChildItem $tmpPath){ 
    Get-Content $item.FullName | Out-File -Append -FilePath "D:\tmp\$(get-date -f MM-dd-yyyy).txt" 
} 
+0

도움 주셔서 감사합니다. 두 옵션을 모두 사용했습니다. – eclipsedlamp

관련 문제