Jump to content
Sign in to follow this  
AntiVirusGuy

Strings

Recommended Posts

AntiVirusGuy

ok ill try to explain

$var1=C:\Program Files\WinRAR\winrar.exe

I want

$var2 to equal the file name in this case "winrar.exe" and I want

$var3 to equal the path in this case "C:\Program Files\WinRAR\"

does anyone know how to do this I tried

$var2 = Stringright($var1, StringInStr($var1, '\', 0, -1) -1)

Help

Share this post


Link to post
Share on other sites
Don N

Try this

$var1="C:\Program Files\WinRAR\winrar.exe"

$var2 = StringRight($var1, StringLen( $var1 ) - StringInStr($var1, '\', 0, -1) )
$var3 = StringLeft($var1, StringInStr($var1, '\', 0, -1) )

MsgBox( 0, "", $var1 & @CR & $var2 & @CR & $var3 )

hope that clears everything up

Edited by Don N

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites
BigDod

Try

$var1 = "c:\Program Files\WinRAR\winrar.exe"
$sect = StringSplit($var1,"\")
$var2 = $sect[1] & "\" & $sect[2] & "\" & $sect[3]
MsgBox(0,"",$var2)
$var3 = $sect[4]
MsgBox(0,"",$var3)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
AntiVirusGuy

Thanks guys Don N just what I wanted thanks BigDod not knowing how long the path is that may not work however I think you may have solved a future problem I have not arrived at yet thanks you both

Share this post


Link to post
Share on other sites
Don N

For variable length path you can use mine or this modified version of bigdod's

$var1 = "c:\Program Files\WinRAR\winrar.exe"
$sect = StringSplit($var1,"\")
$var2 = ""
For $i = 1 To UBound( $sect ) - 2
        $var2 = $var2 & sect[$i] & "\"
Next
MsgBox(0,"",$var2)
$var3 = $sect[UBound($sect) - 1]
MsgBox(0,"",$var3)

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×