TuMiM Posted June 9, 2010 Share Posted June 9, 2010 I know this is probably easy but I can't figure out the easiest way to do it. If i have a string that comes from a fileopendialog that looks like this \\172.28.206.7\Bservices\LST\AB\file.txt and I need to get only the last directory name so AB in this instance. how can i extract that out keeping in mind that that AB can be other directories named other things. Link to comment Share on other sites More sharing options...
JohnOne Posted June 9, 2010 Share Posted June 9, 2010 (edited) Well regexp would do it, but so will stringsplit example $string = "\\172.28.206.7\Bservices\LST\AB\file.txt" $split = StringSplit($string,"\",3) $dir = $split[Ubound($split)-2] ConsoleWrite($dir & @CRLF) Edited June 9, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Mobius Posted June 9, 2010 Share Posted June 9, 2010 (edited) ~ Edited March 2, 2011 by Mobius Link to comment Share on other sites More sharing options...
UEZ Posted June 9, 2010 Share Posted June 9, 2010 This works, too! #Include <String.au3> $string = "\\172.28.206.7\Bservices\LST\AB\file.txt" $array = _StringExplode($string, "\") If IsArray($array) Then MsgBox(0, "Test", $array[UBound($array) - 2]) BR, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Malkey Posted June 9, 2010 Share Posted June 9, 2010 Another two methods. Local $string = "\\172.28.206.7\Bservices\LST\AB\file.txt" Local $Penultimate = StringInStr($string, "\", 0, -2) + 1 MsgBox(0, "StringMid", StringMid($string, $Penultimate, StringInStr($string, "\", 0, -1) - $Penultimate)) ; or MsgBox(0, "StringRegExpReplace", StringRegExpReplace($string, "(?:^.*\\)(.*)(\\.*$)", "\1")) Link to comment Share on other sites More sharing options...
AlmarM Posted June 9, 2010 Share Posted June 9, 2010 Local $String = "\\172.28.206.7\Bservices\LST\AB\file.txt" Local $Split = StringSplit($String, "\") MsgBox(0, "", $Split[$Split[0] - 1]) This works.. :] Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now