0

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.I got it to work using $result.filepath = $pst.FilePath.Split('\')[2,4] -join '/ -replace('RMS/') but i like your solution better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.