/ Published in: Windows PowerShell

replace foo -> bar in all .txt files down the tree
Dunno why, the syntax highlighter adds \3's to the code. Try plain text.
Expand |
Embed | Plain Text
# Select files $files = gci . -recurse | ? { ($_\3 -match "txt$") -and ((gc $_\3.VersionInfo.FileName) -match "the_sink") } | % { $_\3.VersionInfo.FileName } # Back'em up, just in case: $files | % { cp $_\3 "$($_).bak" } # Replace $files | %{ (gc $_\3) -replace "foo","bar" | sc -Path $_\3 }
You need to login to post a comment.