radish Posted April 2, 2020 Report post Posted April 2, 2020 $a = "C:\Program Files (x86)\Google\Chrome\Application\80.0.3987.149\Installer\setup.exe --uninstall --system-level --verbose-logging" $a -replace '([^\\]*)$' Suppose my condition is like this How do I extract the desired folder name $b = $a -replace '([^\\]*)$' $b = google or $b =chrome or $b = Application Quote Share this post Link to post Share on other sites More sharing options...
0 radish Posted April 4, 2020 Report post Posted April 4, 2020 On 4/2/2020 at 7:10 PM, radish said: $a = "C:\Program Files (x86)\Google\Chrome\Application\80.0.3987.149\Installer\setup.exe --uninstall --system-level --verbose-logging" $a -replace '([^\\]*)$' Suppose my condition is like this How do I extract the desired folder name $b = $a -replace '([^\\]*)$' $b = google or $b =chrome or $b = Application This can be solved by taking the folder name $a.split('\')[2] -replace '\.\w+$' google $a.Substring(0,$f.LastIndexOf('.')).split('\')[2] google Quote Share this post Link to post Share on other sites More sharing options...
$a = "C:\Program Files (x86)\Google\Chrome\Application\80.0.3987.149\Installer\setup.exe --uninstall --system-level --verbose-logging"
$a -replace '([^\\]*)$'
Suppose my condition is like this
How do I extract the desired folder name
$b = $a -replace '([^\\]*)$'
$b = google
or
$b =chrome
or
$b = Application
Share this post
Link to post
Share on other sites