easiest way to read all lines from all files in a directory in powershell

StackOverflow https://stackoverflow.com/questions/2541693

  •  23-09-2019
  •  | 
  •  

문제

This expression seems to work:

gci . | % { gc $_}

This also seem to work as well (I suspect it is a little slower):

gci . | Select-String . 

Is there a better way of writing a expression to dump all lines from all files out in a directory?

Thanks

도움이 되었습니까?

해결책

Well you don't want to throw directories at Get-Content. Try this to filter out dirs:

Get-ChildItem | Where {!$_.PSIsContainer} | Get-Content

or using aliases:

gci | ?{!$_.PSIsContainer} | gc

Also note that Get-Content takes the filename as pipeline input so you don't need the Foreach-Object cmdlet. You can pipe directly to Get-Content.

다른 팁

Won't this one do?

gc * -ea SilentlyContinue
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top