The Computer Oracle

have Powershell get-childitem return files only

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Ancient Construction

--

Chapters
00:00 Have Powershell Get-Childitem Return Files Only
00:21 Answer 1 Score 161
00:40 Accepted Answer Score 102
00:54 Answer 3 Score 0
01:11 Thank you

--

Full question
https://superuser.com/questions/150748/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#powershell

#avk47



ANSWER 1

Score 161


In Powershell 3.0, it is simpler,

gci -Directory #List only directories
gci -File #List only files

This is even shorter,

gci -ad # alias for -Directory
gci -af # alias for -File



ACCEPTED ANSWER

Score 102


Try this:

gci . *.* -rec | where { ! $_.PSIsContainer }



ANSWER 3

Score 0


This is not working when anyone named the folder xxx.PDF:

get-childitem -Recurse -include *.pdf

Best then you can do:

Get-ChildItem -Recurse -Include *.pdf | where { ! $_.PSIsContainer }