【发布时间】:2019-12-23 13:52:23
【问题描述】:
尝试遍历包含多个 html 文件的文件夹/子文件夹以查找特定字符串/单词。
一旦 powershell 脚本找到它 - 它将列出哪些文件包含匹配的单词。 可能会提示用户替换单词或设置变量,例如 $replaceword = 'test2'
$match = "THIS IS A TEST"
#$replacement = Read-Host "Please enter a solution name"
$files = Get-ChildItem -path C:\Users\testfolder -filter *THIS IS A TEST* -Recurse
$files
Sort-Object -Descending -Property { $_.FullName }
#Rename-Item -newname { $_.name -replace $match, $replacement } -force
$files = Get-ChildItem -path C:\Users\testfolder -include *.html -Recurse
foreach($file in $files)
{
((Get-Content $file.fullname) -creplace $match)
read-host -prompt "Done! Press any key to close."
}
【问题讨论】:
-
您要替换匹配的文件名或文件内容吗?
-
这些 html 文件中的单词/字符串.. 不是文件名
标签: powershell