且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 PowerShell 遍历目录中的文件

更新时间:2023-01-16 15:04:27

试试这个:

Get-ChildItem "C:\Users\gerhardl\Documents\My Received Files" -Filter *.log | 
Foreach-Object {
    $content = Get-Content $_.FullName

    #filter and save content to the original file
    $content | Where-Object {$_ -match 'step[49]'} | Set-Content $_.FullName

    #filter and save content to a new file 
    $content | Where-Object {$_ -match 'step[49]'} | Set-Content ($_.BaseName + '_out.log')
}