Powershell在每个C文件的备份上设置头
我需要一个动态的解决方案来解决这个问题: 在Powershell中,我需要创建一个脚本/CMDLET,用于在所有C文件上设置特定的头(文本) 谢谢您的支持。您可以试试这个,包括docu 简而言之,它具有以下功能:Powershell在每个C文件的备份上设置头,powershell,Powershell,我需要一个动态的解决方案来解决这个问题: 在Powershell中,我需要创建一个脚本/CMDLET,用于在所有C文件上设置特定的头(文本) 谢谢您的支持。您可以试试这个,包括docu 简而言之,它具有以下功能: function Add-FileHeader { [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [ValidateScript({ Test-Path $_
function Add-FileHeader {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateScript({ Test-Path $_ })]
[string] $DirectoryToSearchThrough,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty ()]
[ValidateScript({ $_ -ge 1 })]
[string[]] $IncludeFilePattern,
[Parameter(Mandatory=$true)]
[ValidateNotNull()]
[string] $FileHeaderToAdd,
[Parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty ()]
[ValidateScript({ $_ -ge 1 })]
[string[]] $ExcludeFilePattern
)
Get-ChildItem -Path $DirectoryToSearchThrough -Include $IncludeFilePattern -Exclude $ExcludeFilePattern -Recurse | `
ForEach-Object {
Write-Host "Working on $($_.Name)"
$content = Get-Content $_;
Set-Content -Path $_.FullName -Value $FileHeaderToAdd, $content;
}
}
希望这能有所帮助。到目前为止,您尝试了哪些方法/哪些方法对您无效?您好,Manuel,欢迎来到StackOverflow。你的问题有点不清楚。“动态解决方案方法”的特征是什么?到目前为止,你为实现目标做了哪些努力?当你在C文件中说“设置一个特定的头”时,你是在说向一堆源文件中添加
#include
预处理语句还是其他什么?所有文件的编码是否一致?请提供更多详细信息,最好是更改前后的文件示例。我所说的动态解决方案是指它可以应用于特定目录中的每个C文件。还有由#include函数实现的头。