gpt4 book ai didi

windows - 用于查找给定字符串并替换给定目录中所有文件的脚本

转载 作者:可可西里 更新时间:2023-11-01 12:04:45 25 4
gpt4 key购买 nike

如何在 powershell 中编写脚本,在给定目录的所有文件中找到给定的字符串并将其更改为给定的第二个字符串?

感谢您的帮助,再见

最佳答案

也许是这样的

    $files = Get-ChildItem "DirectoryContainingFiles"
foreach ($file in $files)
{
$content = Get-Content -path $file.fullname
$content | foreach {$_ -replace "toreplace", "replacewith"} |
Set-Content $file.fullname
}

关于windows - 用于查找给定字符串并替换给定目录中所有文件的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6228911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com