Manipulating File System Paths

by Sep 4, 2013

PowerShell lets you access multiple array elements. With the help of -split and -join, you can easily manipulate file system paths this way.

To exclude the second and third level folder, try this:

$path = 'C:\users\Tobias\Desktop\functions.ps1'

$array = $path -split '\\'
$newpath = $array[0,3,4]
$newpath -join '\' 

To rename the second subfolder, try this:

$path = 'C:\users\Tobias\Desktop\functions.ps1'

$array = $path -split '\\'
$array[2] = 'OtherUser'
$array -join '\'

Twitter This Tip! ReTweet this Tip!