Here is my scenario:
I have a text file containing many lines. Each line is a folder path.
Example: 000.txt
C:\Program Files (x86)\Microsoft Office\Office15
C:\Program Files (x86)\Common Files\Adobe\Acrobat
C:\Program Files (x86)\Common Files\Blizzard Entertainment
I need to find a way to get the name of the last child folder for each row and use it to create a link to the folder:
d:\>mklink /j office15 "C:\Program Files (x86)\Microsoft Office\Office15"
d:\>mklink /j acrobat "C:\Program Files (x86)\Common Files\Adobe\Acrobat"
d:\>mklink /j "Blizzard Entertainment" "C:\Program Files (x86)\Common Files\Blizzard Entertainment"
I tried this:
$a="C:\Program Files (x86)\Microsoft Office\Office15"
$a.Split()[-1]
As a result:
Office\Office15
I also tried:
$a.Split("`t",[System.StringSplitOptions]::RemoveEmptyEntries)[-1]
And the result:
5
How to get the last word of each line or word after the last \using Batch or PowerShell?
source
share