Add text to multiple files via powershell

送分小仙女□ 提交于 2019-12-11 07:56:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!