Useful Path Manipulation Shortcuts

by Sep 8, 2014

All PowerShell Versions

Here are a bunch of useful (and simple to use) system functions for dealing with file paths:

[System.IO.Path]::GetFileNameWithoutExtension('file.ps1')
[System.IO.Path]::GetExtension('file.ps1')
[System.IO.Path]::ChangeExtension('file.ps1', '.copy.ps1')

[System.IO.Path]::GetFileNameWithoutExtension('c:\test\file.ps1')
[System.IO.Path]::GetExtension('c:\test\file.ps1')
[System.IO.Path]::ChangeExtension('c:\test\file.ps1', '.bak')

All of these methods accept either file names or full paths, and return different aspects of the path, or change things like the extension.

Twitter This Tip! ReTweet this Tip!