2012-12-17 99 views
4

我試圖找到使用PowerShell遞歸的一行代碼。管道文件獲取內容

要尋找一個已知文件行「TODO:」我可以這樣做:

get-content ActivityLibrary\Accept.cs | select-string TODO 

但我不想明確鍵入每個目錄\文件。我想管,從GET-childitem了一系列的文件名是這樣的:

gci -filter *.cs -name -recurse | gc | select-string TODO 

但後來我看到這個錯誤:

Get-Content : The input object cannot be bound to any parameters for the comman d either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:37

我在做什麼錯?

回答

8

您需要刪除-Name開關。它只輸出文件名,而不是文件對象。你也可以直接管道選擇字符串並刪除'gc'。

+0

不錯。取出gc會增加行號。我習慣了Linux CLI,因此對象/字符串的區別對我來說是新的。 – micahhoover