我想知道我将如何做到这一点。我有一个可以包含多个文件的目录,它们的名称不同,但它们都具有相同的扩展名(.ini)。我需要以某种方式,通过他们的扩展名搜索文件,然后依次订购替换每个文件中的内容。现在我想出了如何通过确切名称(而不是扩展名)获取文件并替换它的内容
@powershell -command "(Get-Content ..\Folder\File.ini).replace('TextToBeReplaced',\"NewText1`nNewText2") | Set-Content ..\Folder\File.ini"
我需要改变什么?
答案 0 :(得分:5)
试试这个:
Get-ChildItem "c:\temp\" -recurse -file -filter "*.ini" |
%{$fullname=$_.fullname; (Get-Content $_.fullname).Replace("oldstring", "newstring") | Set-Content $fullname}
答案 1 :(得分:2)
最简单的方法是将-Filter
参数与Get-ChildItem
:
Get-ChildItem -Filter *.ext -Recurse