PowerShell Hack: Mit diesem PowerShell-Skript kannst du Text in mehreren Dateien ersetzen.
Ich habe ein kleines PowerShell-Skript für Windows geschrieben, um Text in einem ganzen Verzeichnis und dessen Unterverzeichnissen zu ersetzen.
Das kann manchmal ganz praktisch sein, wenn man zum Beispiel in einem ganzen Ordner mit html-Dateien, etwas in allen Dateien ersetzen möchte und das Projekt nicht in Visual Studio geöffnet hat.
Das folgende Skript ersetzt im aktuellen Verzeichnis und dessen Unterverzeichnissen in allen Textdateien (*.txt) den Text "search" mit "substitute".
$files = Get-ChildItem . *.txt -rec
foreach ($file in $files)
{
(Get-Content -Raw $file.PSPath) -replace "search", "substitute" |
Set-Content $file.PSPath
}
Vorsicht: Bevor man das Skript verwendet, empfehle ich das angepasste Skript in einem Testordner zu testen und ein Backup des Ordners zu erstellen, auf dem man das Skript anwenden möchte.
PowerShell Hack: With this PowerShell script you can replace text in multiple files.
I wrote a small PowerShell script for Windows to replace text in an entire directory and its subdirectories.
This can sometimes come in handy if, for example, you want to replace something in a folder of html files and you don't have the project open in Visual Studio.
The following script replaces the text "search" with "substitute" in the current directory and its subdirectories in all text files (.txt).*
$files = Get-ChildItem . *.txt -rec
foreach ($file in $files)
{
(Get-Content -Raw $file.PSPath) -replace "search", "substitute" |
Set-Content $file.PSPath
}
Caution: Before using the script, I recommend testing the customized script in a test folder and making a backup of the folder where you want to apply the script to.
Live your Secrets and Steem Prosper 🔥
xx Viki @vikisecrets
Blog post: Text in mehreren Dateien (in einem ganzen Verzeichnis) mit der Windows PowerShell ersetzen