Parse and build paths with Split-Path and Join-Path
Stop slicing strings with .Substring() — PowerShell has dedicated cmdlets to pull apart and reassemble file paths.
01Command
$ Split-Path 'C:\Work\report.csv' -Leaf ; Split-Path 'C:\Work\report.csv' -Extension ; Join-Path 'D:\Backup' '2026\logs'02What it does
These two cmdlets are forgotten because people hard-code '\' string surgery, which breaks on UNC paths and registry keys. Split-Path also supports -Resolve to verify the parent actually exists, and pipelines naturally from Get-ChildItem. Join-Path inserts the correct separator for the active provider and handles a trailing slash on the parent gracefully.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Join-Path | Microsoft LearnEvidence: Microsoft documents Join-Path combining a parent path and child path with the provider's correct separator.
- Split-Path | Microsoft LearnEvidence: Microsoft documents Split-Path with -Parent, -Leaf, -Extension, -NoQualifier, -Qualifier and -Resolve parameters.
Last verified: 2026-09-17 · Category: Files & Folders
06Related solutions
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.
Search inside text files and logs with regex, returning file, line number and match.