如何自动批量编辑位于 Win 8.1 目录中的文本文件?

How can I automate a mass edit of text files located in a Win 8.1 directory?

美好的一天,

在Win 8.1下的特定目录下,我有这数百个扩展名为*.xml的文本文件,代表一个网站。

在这些文件中的每一个中,都恰好出现了一次具有已知内容的特定标签,比如 <tag>old</tag>

在所有这些页面中,此特定文本需要替换为 <tag>new</tag>。子目录存在,但不需要检查。

我如何自动执行此任务? (我不熟悉 PowerShell,我想我从来没有用过它,但它会朝着正确的方向前进吗?如果不是 - 对误导性标签表示歉意。)

提前致谢!

检查replacer.bat

for %%# in (*.xml) do (
   call replacer.bat "%%~f#" "<tag>old</tag>" "<tag>new</tag>"
)

试试这个 PowerShell 脚本。

$myFiles=get-childitem C:\Folder *.xml -rec
foreach ($file in $myFiles)
{
    (Get-Content $file.PSPath) | 
    Foreach-Object {$_ -replace "<tag>old</tag>", "<tag>new</tag>"} | 
    Set-Content $file.PSPath
}