PowerShell: List Files

By Xah Lee. Date: . Last updated: .

💡 TIP: Command names and parameter names are case-insensitive.

List Files

List file in current directory.

# 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
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

List Files

Create, Copy, Delete, Dir

Path Tutorial