Share via


How to list only Files Or Directory using PowerShell?

During a short discussion about files system in PowerShell, I got a question.

Can we list only files using PowerShell?

Quick Way

[System.IO.Directory]::GetFiles('C:\')

Alternate Methods
PowerShell 3.0 and Above
Before we do something in PowerShell - It's better to check the version and explore :) . My way of PowerShell scripting

Get-ChildItem C:\ -File            
            
#Returns Only Files
            
Get-ChildItem C:\ -Directory            
            
#Returns Only Directories

Enjoy PowerShell :)

See Also