PowerShell tip: working with path names with Join-Path, Resolve-Path and Split-Path

Posted: (EET/GMT+2)

 

PowerShell has helpful cmdlets for working with file system paths and filenames. So, you do not have to worry about manual string concatenation or separator differences. Here's a quick summary of few cmdlets in action.

The Join-Path combines path segments safely:

$root = "C:\Data"
$sub  = "Logs"
$path = Join-Path $root $sub   # C:\Data\Logs

The Resolve-Path turns a relative or wildcard path into a full path:

Resolve-Path .\*.txt | Select-Object Path

This is useful when you need absolute paths for external tools.

The Split-Path breaks a path into pieces:

$full = "C:\Data\Logs\app.log"

Split-Path $full                 # C:\Data\Logs
Split-Path $full -Leaf           # app.log
Split-Path $full -Parent         # C:\Data\Logs
Split-Path $full -Qualifier      # C:

These cmdlets make your scripts more robust and readable, especially when building dynamic paths or running scripts on different machines where base folders vary.