maro-k
June 29, 2020, 6:22am
1
Hello
I have variable $path . It contains more than 2 paths like:
C:\user\mark\dekstop\file1.txt
C:\user\tom\dekstop\file2.txt
C:\user\mark\download\file3.txt
I need to trim $path (last *.txt) to : (expectenced)
C:\user\tom\dekstop\
C:\user\mark\dekstop\
Does anyone have ane idea how to trim it?
Olaf
June 29, 2020, 6:46am
2
Did you try to search for it? There’s even a builtin cmdlet for Split-Path !!!
maro-k
June 29, 2020, 7:03am
3
Yes I treid. I was focused to manipulation text with split, splitend and indexof. i did’n knwo split-path cmdlet
or you could use both split and trim like:
($path.Split(‘;’)).trim(‘*.txt’)
Olaf
June 30, 2020, 11:16am
5
I’m afraid the .trim() method does not work like you think it does. Try the following snippet. It might help you to understand
'trim specified charachters'.trim('srthcae')
riedyw
June 30, 2020, 11:25am
6
Use the Split-Path command. Of course since your original variable is an array of paths you will need to iterate through that array and run the Split-Path on each element of the array.