2012-11-29 38 views
0

我試圖自定義這裏描述的代碼PowerShell add text line to multiple files 我的情況。我有多個只有數字的csv文件,在第一行我想要一個特定的短語(例如流域降雨量文件)。 我做了以下內容: >通過PowerShell添加文本到多個文件

[email protected]" 
>"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" 
>} 

在哪裏我錯了有什麼想法? 非常感謝。

+0

什麼是錯誤?順便說一句,驗證代碼:在第2行開始時你有一個'''。你的代碼在其他地方似乎沒問題......當你刪除'| Set-Content'時輸出是什麼? –

+0

humm ..在foreach對象中似乎有問題與''' –

+1

錯誤是:在表達式或語句中出現意外的令牌「n」+(Get-Content $ _。FullName | Out-String)| Set-Content -P ath $ _。FullName「'。 At line:2 char:86 + $ header'n「+(Get-Content $ _。FullName | Out-String)| Set-Content -Path $ _。F ullName」<<<< + CategoryInfo: ParserError:('n「+(Get-Cont ... th $ _。FullName」: String)[],ParentContainsErrorRecordException + FullyQualifiedErrorId:UnexpectedToken – Mary

回答

0

感謝大家的幫助。我終於想出了這個工作原理:

[email protected]" 
catchment rainfall 
"@ 
Get-ChildItem .\testing\ -Recurse -Filter *.csv| Foreach-Object { $header+"`n"+ (Get-Content $_.FullName | Out-String) | Set-Content -Path $_.FullName} 
相關問題