我尝试过使用下面的代码,但我想它不会起作用,因为''之间的任何内容都被视为一个字符串。需要以某种方式包含此$ count变量。我知道这是基本的问题,但我刚刚开始使用PowerShell,我在网上找不到任何东西。感谢
$count = 1
Get-ChildItem C:\Users\boris.trninic\Desktop\current\AM-2794\Corr_Distribution *.aaj -recurse |
Foreach-Object {
$count += 1
$c = ($_ | Get-Content)
$c = $c -replace 'Fixed_Seed=1','Fixed_Seed=$count'
[IO.File]::WriteAllText($_.FullName, ($c -join "`r`n"))
}
答案 0 :(得分:0)
您需要使用双引号:
$count = 1
Get-ChildItem C:\Users\boris.trninic\Desktop\current\AM-2794\Corr_Distribution *.aaj -recurse |
Foreach-Object {
$count++
$c = ($_ | Get-Content)
$c = $c -replace "Fixed_Seed=1","Fixed_Seed=$count"
[IO.File]::WriteAllText($_.FullName, ($c -join "`r`n"))
}