PowerShell: Path Tutorial

By Xah Lee. Date: . Last updated: .

Path parameter

Many commands have a -Path parameter.

Path parameter is a positional parameter and named parameter. That means, it can be first arg, or with -path value anywhere.

# list file of a given path
dir c:/Users/xah/web/
# or
dir -Path c:/Users/xah/web/

If Path parameter is omitted, default value is current dir.

# same as
dir .

Path value can contain abbrev, such as ~/ to mean $home, and String Wildcards such as * for any characters.

dir ~/web/
# same as
dir c:/Users/xah/web/

Use -LiteralPath if you do not want expansion.

Relative Path, Full Path

The -Path parameter accepts both full path or relative path.


dir Documents
# same as
dir c:/Users/xah/Documents/

quote path that contains space

If the path contains space, it needs to be quoted.

dir "c:/Users/xah/Saved Games"

[see PowerShell: String]

Note: quoted path is also expanded.

# works
dir "~/web/"

Path separator

Path separator is the backslash, but slash is also supported. They can be mixed.

All the following works the same:

single dot, double dots

For example:

current dir

Get-Location (alias gl, pwd) return the current dir.

Path expansion

Path allows String Wildcards or other shortcut such as ~/ to mean home dir.

To see what a given path expand to, use Resolve-Path.

Resolve-Path ~/

# Path
# ----
# C:\Users\xah
Resolve-Path "~/Documents/*"

# Path
# ----
# C:\Users\xah\Documents\PowerShell
# C:\Users\xah\Documents\Wolfram Desktop
# C:\Users\xah\Documents\wolframlang


The -LiteralPath parameter lets you input a path without expansion.

# list children of a dir named math* as is
dir -LiteralPath "math*"

PowerShell Path


Practical How-To

list files

list dirs

on dir

on file

Windows config


PowerShell in Depth

Programing PowerShell

Value Types





Data Structure

Loop and Iteration



Profile and Script

Script Examples