我可以帮助您翻译。以下是需要翻译的内容:
我有以下脚本:
$allFiles = Get-ChildItem "./" -Recurse | Where { ($_.Extension -eq ".ts")}
foreach($file in $allFiles)
{
# Find and replace the dash cased the contents of the files
(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace "my-project-name", '$appNameDashCased$'} |
Set-Content $file.PSPath
# Find and replace the dash cased the contents of the files
(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace "MyProjectName", '$appNameCamelCased$'} |
Set-Content $file.PSPath
# Find and replace the dash cased the contents of the files
(Get-Content $file.PSPath) |
Foreach-Object {$_ -replace "myProjectName", '$appNamePascalCased$'} |
Set-Content $file.PSPath
}
它需要一个文件并进行一些替换,然后保存该文件。 然后它取出相同的文件并进行更多的替换,然后再次保存文件。 然后再做一次。
这个方法可以起作用,但似乎效率低下。
有没有一种方法可以先执行所有替换操作,然后再保存文件一次?
(如果可能,我希望保留PowerShell的易读样式。)
$allFiles = Get-ChildItem -recurse -Include "*.ts"
。对于Get-Content,你只需要使用$file对象。Get-Content $file
。 - Jeter-work