Reputation: 143
I have a file path
e:\pst\Section\RMS\user\\
final output needs to be Section/user
Currently using
$result.filepath = $pst.FilePath.Split('\')[2..4] -join '/'
but that gives me
Section/RMR/User
How can I manipulate the split to only pull 2 and 4 to equal Section/User?
Upvotes: 0
Views: 58
Reputation: 19684
You have an error in your example:
$pst = 'e:\pst\Section\RMS\user\'
$result.filepath = $pst.FilePath.Split('\')[2..4] -join '/'
$result.filepath
Section/RMS/user
Should be:
$pst = 'e:\pst\Section\RMS\user\'
$result.filepath = $pst.FilePath.Split('\')[2,4] -join '/'
$result.filepath
Section/user
Note the comma instead of the range operation.
Upvotes: 3