管道文件以获取内容 [英] piping files to get-content
问题描述
我正在尝试使用 powershell 递归查找一行代码.
I'm trying to find a single line of code recursively using powershell.
要在已知文件中查找TODO"行,我可以这样做:
To look for the line "TODO" in a known file I can do:
get-content ActivityLibrary\Accept.cs | select-string TODO
但我不想明确键入每个目录\文件.我想从这样的 get-childitem 管道中输入一系列文件名:
But I don't want to explicitly type every directory\file. I would like to pipe a series of filenames from get-childitem like this:
gci -filter *.cs -name -recurse | gc | select-string TODO
但后来我看到了这个错误:
But then I see this error:
Get-Content : 输入对象不能绑定到任何参数命令 d 要么是因为该命令不接受管道输入或输入及其属性与任何参数不匹配采取管道输入.在行:1 字符:37
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
我做错了什么?
推荐答案
您需要删除 -Name 开关.它只输出文件名,不输出文件对象.您也可以直接通过管道连接到 Select-String 并删除 'gc'.
You need to remove the -Name switch. It outputs just file names, not file objects. And you can also pipe directly to Select-String and drop 'gc'.
这篇关于管道文件以获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!