问题
I am trying to customise the code described here PowerShell add text line to multiple files to my case. I have multiple csv files with numbers only and on the first line I would like to have a specific phrase (e.g catchment rainfall file). I am doing the following: >
$header=@"
>"catchment rainfall
>"@
>Get-ChildItem D:\Documents and Settings\mary\testing\mary00 -Recurse -Filter *.aspx | >Foreach-Object {
> $header`n" + (Get-Content $_.FullName | Out-String) | Set-Content -Path $_.FullName"
>}
Any thoughts on where I am going wrong? Thanks so much.
回答1:
thanks everyone for their help. I have finally come up with this which works:
$header=@"
catchment rainfall
"@
Get-ChildItem .\testing\ -Recurse -Filter *.csv| Foreach-Object { $header+"`n"+ (Get-Content $_.FullName | Out-String) | Set-Content -Path $_.FullName}
来源:https://stackoverflow.com/questions/13619699/add-text-to-multiple-files-via-powershell