PowerShell: LiteralPath parameter

By Xah Lee. Date: . Last updated: .

LiteralPath

The -LiteralPath parameter lets you input a path without Path Expansion .

# list children of a dir name containing asterisk
dir -LiteralPath 'p*'

🛑 WARNING: -LiteralPath with double quote still go thru String Expansion

# -LiteralPath with double quote still do string expansion

$x = 'bbb'

dir -LiteralPath "$x"
# same as
# dir -LiteralPath 'bbb'

# Get-ChildItem: C:\Users\xah\.emacs.d\temp\20250502_2025_7d0b.ps1:5
# Line |
   # 5 |  dir -LiteralPath "$x"
     # |  ~~~~~~~~~~~~~~~~~~~~~
     # | Cannot find path 'C:\Users\xah\.emacs.d\temp\bbb' because it does not exist.

PowerShell. Path