PowerShell: List Files
💡 TIP: Command names and parameter names are case-insensitive.
List Files
List file in current directory.
Get-ChildItem
has aliasdir
# list files in current dir dir # full path dir "c:/Program Files/Windows Defender" # relative path dir Documents # using home dir abbrev dir ~/Documents/
If path contain space, need quote. 〔see Path Tutorial〕
Wildcard in Path
Path can contain Wildcards such as *
.
# list files whose name ends in jpg in current dir dir *jpg
〔see Path Tutorial〕
LiteralPath
if you do not want special interpretation of path, use
-LiteralPath
.
# list files in a dir whose name is just a asterisk dir -LiteralPath '*'
Show Subdirectories (Recurse and Depth)
list files in current dir, and all subdirectories, any depth:
-recurse
dir -recurse
-depth 0
is same as no recurse.-depth 1
means include children of first-level subdirectories.-depth 2
means up to second-level subdirectories, etc.
dir -depth 1
Show file name only
# list file names dir -recurse -name # result paths are relative to current dir
Show Hidden Files and System Files
dir -Force
〔see Get/Set File Attributes〕
List Only Files, No Directory
dir -file
# list only dirs dir -directory
PowerShell, List Dirs and Files
List Dirs
- PowerShell: Navigate Directory
- PowerShell: Show Current Dir Path
- PowerShell: List Directories
- Show Directory as Tree
- PowerShell: List Empty Dir 🚀
- PowerShell: Dir Size 🚀
List Files
- PowerShell: List Files
- PowerShell: Show Fullpath, No Truncate Lines
- PowerShell: List Empty Files
- PowerShell: Count Number of Files
- PowerShell: List Files by Name Pattern
- PowerShell: Filter File Name by Regular Expression
- PowerShell: List File by Size
- PowerShell: Sort Files by File Size 🚀
- PowerShell: List Files by Date Time
- PowerShell: Search Text in Files (grep)