Mick Posted May 15, 2006 Share Posted May 15, 2006 I couldn't find this anywhere else, so I wrote a script to separate a pathname and filename from a full path/filename. ; Splits the filepath into DIR or FILENAME, pass full filepath as VAR1, required part as VAR2 ; eg Pass (C:\Windows\System32\notepad.exe, 0) to return C:\Windows\System32 ; eg Pass (C:\Windows\System32\notepad.exe, 1) to return notepad.exe Func _SplitFilePath($VAR1, $VAR2) $PathBits = StringSplit ($VAR1, "\") $SplitFileName = $PathBits[$PathBits[0]] If $VAR2 = 0 Then $ReturnValue = StringTrimRight ($VAR1, StringLen ($SplitFileName) + 1) Else $ReturnValue = $SplitFileName EndIf Return $ReturnValue EndFunc If this already exists as a function can someone point it out please? Otherwise, could it be added to next BETA as it's quite useful (to me at least). Thanks. Link to comment Share on other sites More sharing options...
Micha1405 Posted May 15, 2006 Share Posted May 15, 2006 Nice another solution $filepath = "c:\Windows\notepad.exe" $file = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1)) $Path = StringLeft($filepath,StringInStr($filepath,"\",0,-1)-1) MSGBOX(0,"Result",$Path &" | "&$file) My TrayToolBar Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 15, 2006 Share Posted May 15, 2006 HI, right from help. #include <file.au3> #include <array.au3> Dim $szDrive, $szDir, $szFName, $szExt $TestPath = _PathSplit(@ScriptFullPath, $szDrive, $szDir, $szFName, $szExt) _ArrayDisplay($TestPath,"Demo _PathSplit()") So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Simucal Posted May 15, 2006 Share Posted May 15, 2006 Like th.meger said, _PathSplit is the way to go. However, here is my crack at doing it in one less line than Micha: $filepath = "c:\Windows\notepad.exe" $a_result = stringregexp($filepath,'([a-zA-Z]:\\[^/:*?"<>|\r\n]*[\\])([^/:*?"<>|\r\n]*\.[a-zA-Z0-9]{3})',1) If IsArray($a_result) Then MSGBOX(0,"Result","Path: "&$a_result[0] &@CRLF&"File: "&$a_result[1]) AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 15, 2006 Share Posted May 15, 2006 (edited) Like th.meger said, _PathSplit is the way to go. However, here is my crack at doing it in one less line than Micha: $filepath = "c:\Windows\notepad.exe" $a_result = stringregexp($filepath,'([a-zA-Z]:\\[^/:*?"<>|\r\n]*[\\])([^/:*?"<>|\r\n]*\.[a-zA-Z0-9]{3})',1) If IsArray($a_result) Then MSGBOX(0,"Result","Path: "&$a_result[0] &@CRLF&"File: "&$a_result[1]) HI, NICE, but you have to change a little bit, otherwise it only works if the extension is 3 chars long. What about e.g config.properties files So long, Mega Edited May 15, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
AutoItKing Posted May 15, 2006 Share Posted May 15, 2006 Try this: Func _Extenstion($filename) $string=StringSplit($filename,".") Return $string[$string[0]] EndFunc http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script] 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