Replace String in file contents and file names using PowerShell
Copy this code and paste it in your HTML
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 $_.Path
) |% { $_ -replace $find, $replace } | set-content $_.Path
-Force } ls $path\
*$find* |% { echo "Renaming $($_.FullName) to $($_.FullName.Replace($find, $replace))";
mv $_.FullName
$_.FullName.Replace
($find, $replace) } }
# Example
Replace-String "Temp1" "Temp2" "D:\Temp"
Report this snippet
Comments
Subscribe to comments