Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Created January 6, 2022 15:53
Show Gist options
  • Save JohnL4/87a8a3ae6db73e2a5040019d543dc22e to your computer and use it in GitHub Desktop.
Save JohnL4/87a8a3ae6db73e2a5040019d543dc22e to your computer and use it in GitHub Desktop.
PowerShell filename parts
$f = ls foo/bar.txt
$f | select Directory,DirectoryName,BaseName,Extension
# More generic than just filesystem provider (e.g., registry keys)
$f | split-path -parent # Container
$f | split-path -leaf # Contained child
$f | split-path -noqualifier # Drive letter only or, for example, "HKCU:"
$f | split-path -qualifier # No qualifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment