olympus Posted October 17, 2009 Share Posted October 17, 2009 How do I get the string after the last '\' in a file's address? Let's say the file is located in C:\Program Files\GreatSoftware\link.html. How do I obtain 'link.html' from the full address? I think I should use StringSplit but I'm not familiar with it. Please help, thank you. Link to comment Share on other sites More sharing options...
Yashied Posted October 17, 2009 Share Posted October 17, 2009 (edited) StringRegExpReplace($sPath, "^.*\\", "")Or_PathSplit() Edited October 17, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
water Posted October 17, 2009 Share Posted October 17, 2009 Please see _PathSplit in the help file. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
Bowmore Posted October 17, 2009 Share Posted October 17, 2009 Function _PathSplitThere is also the useful_PathSplit function which splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing.and _PathMake function to put all the parts back together as a valid path. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
olympus Posted October 19, 2009 Author Share Posted October 19, 2009 Function _PathSplitThere is also the useful_PathSplit function which splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing.and _PathMake function to put all the parts back together as a valid path.How do I use _PathSplit? I referred to the help file and I didn't understand the example involving arrays... can someone make an example with a msgbox output? Thank you. Link to comment Share on other sites More sharing options...
GEOSoft Posted October 19, 2009 Share Posted October 19, 2009 Yashied gave you the best solution but I'll turn it into an example $sPath = "C:\Program Files\GreatSoftware\link.html" $sFileName = StringRegExpReplace($sPath, "^.+\\(.*)$", $1) MsgBox(0, "Result", $sfileName) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
olympus Posted October 19, 2009 Author Share Posted October 19, 2009 Yashied gave you the best solution but I'll turn it into an example $sPath = "C:\Program Files\GreatSoftware\link.html" $sFileName = StringRegExpReplace($sPath, "^.+\\(.*)$", $1) MsgBox(0, "Result", $sfileName) Thank you GEO for the example, but what are the meaning of the symbols in between the quotes and teh $1 at the end? Link to comment Share on other sites More sharing options...
Nutster Posted October 19, 2009 Share Posted October 19, 2009 $sPath = "C:\Program Files\GreatSoftware\link.html" $sFileName = StringRegExpReplace($sPath, "^.+\\(.*)$", $1) MsgBox(0, "Result", $sfileName) Take a look at the docs for StringRegExp for a description of what each part of a regular expression does. Let's see: ^ - beginning of string . - any character + - previous character (group/set) one or more times \\ - any actual \. Normally \ is used to escape special characters. ( - begin a capturing group. Contents from this group will go into $1 . - any character (again) * - previous character (or group or set) zero or more times. ) - end capturing group. $ - end of string. David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd... Link to comment Share on other sites More sharing options...
olympus Posted October 19, 2009 Author Share Posted October 19, 2009 Take a look at the docs for StringRegExp for a description of what each part of a regular expression does. Let's see:^ - beginning of string. - any character+ - previous character (group/set) one or more times\\ - any actual \. Normally \ is used to escape special characters.( - begin a capturing group. Contents from this group will go into $1. - any character (again)* - previous character (or group or set) zero or more times.) - end capturing group.$ - end of string.Oh okok. I'll check it out. Thank you! Link to comment Share on other sites More sharing options...
Mison Posted October 19, 2009 Share Posted October 19, 2009 (edited) Hi olympus... that is regular expression string pattern... don't be afraid of that, you'll get used to it... you can also use string split, then take the last element... $folder = FileSelectFolder("Select any folder","") ;select folder, obviously $path_array = StringSplit($folder,"\") ; Split path into an array element $folder_name = $path_array[UBound($path_array)-1] ; take the last element MsgBox(0,"",$folder_name) ; popup message box Edited October 19, 2009 by Mison Hi ;) Link to comment Share on other sites More sharing options...
olympus Posted October 19, 2009 Author Share Posted October 19, 2009 Oh... now I get it, so when we're using the script below: $sPath = "C:\Program Files\GreatSoftware\link.html" StringRegExpReplace($sPath, "^.*\\", "") MsgBox(0, "Result", $sfileName) ...we're telling it to replace all the characters(C:\Program Files\GreatSoftware\ = "^.*\\") before the file name with nothing(""), hence we are only left with the file name(link.html). Thanks people, the examples were helpful. Link to comment Share on other sites More sharing options...
Mison Posted October 19, 2009 Share Posted October 19, 2009 Yupp, that's the idea... replace unwanted characters with empty string("") a.k.a delete them.. ;P Hi ;) 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