String Manipulation

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?

 

Did you try to search for it? There’s even a builtin cmdlet for Split-Path !!!

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’)

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')

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.