Commands / Files

Split-Path

Pull a folder or name out of a path

beginner Files

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

ShellWhat you might type
bash / zshdirname docs/notes.txt

More in From bash and From cmd.

Related commands