Split-Path
Pull a folder or name out of a path
Split-Path -Path .\docs\notes.txt -Parent
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Split-Path
-Parent returns the folder. -Leaf returns the file or last segment. Useful when you have a full path and need one piece.
Try this
Split-Path -Path .\docs\notes.txt -Leaf
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | dirname docs/notes.txt |
More in From bash and From cmd.