/ Published in: Windows PowerShell
Expand |
Embed | Plain Text
function Replace-String($find, $replace, $path) { echo "Replacing string `"$find`" with string `"$replace`" in file contents and file names of path: $path" ls $path | select-string $find -list |% { echo "Processing contents of $($_.Path)"; (get-content $_\3.Path) |% { $_\3 -replace $find, $replace } | set-content $_\3.Path -Force } ls $path\*$find* |% { echo "Renaming $($_.FullName) to $($_.FullName.Replace($find, $replace))";mv $_\3.FullName $_\3.FullName.Replace($find, $replace) } } # Example Replace-String "Temp1" "Temp2" "D:\Temp"
Comments
Subscribe to comments
You need to login to post a comment.

a bit more explanation would be nice.
thanks for the function. I've saved some time with it.