Moderators SmOke_N Posted October 7, 2008 Moderators Posted October 7, 2008 $explorer = "C:\WINDOWS\explorer.exe" ConsoleWrite($explorer&@CRLF&"FileName: "&getFileName($explorer)&@CRLF&"ParentDir: "&getParentDir($explorer)&@CRLF&"Extension: "&getExtension($explorer)&@CRLF) Func getFileName($fpath) Return StringMid($fpath,StringInStr($fpath,"\",0,-1)+1) EndFunc Func getParentDir($fpath) Return StringMid($fpath,1,StringInStr($fpath,"\",0,-1)) EndFunc Func getExtension($fpath) Return StringMid($fpath,StringInStr($fpath,".",0,-1)+1) EndFunc another way That's just a sloooooooooooow way of doing a _PathSplit(). Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
bluelamp Posted October 7, 2008 Posted October 7, 2008 ahhhhm... look at file.au3 in the includedirectory.. i don´t think this is faster, it uses the same functions expandcollapse popupFunc _PathSplit($szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt) ; Set local strings to null (We use local strings in case one of the arguments is the same variable) Local $drive = "" Local $dir = "" Local $fname = "" Local $ext = "" Local $pos ; Create an array which will be filled and returned later Local $array[5] $array[0] = $szPath; $szPath can get destroyed, so it needs set now ; Get drive letter if present (Can be a UNC server) If StringMid($szPath, 2, 1) = ":" Then $drive = StringLeft($szPath, 2) $szPath = StringTrimLeft($szPath, 2) ElseIf StringLeft($szPath, 2) = "\\" Then $szPath = StringTrimLeft($szPath, 2) ; Trim the \\ $pos = StringInStr($szPath, "\") If $pos = 0 Then $pos = StringInStr($szPath, "/") If $pos = 0 Then $drive = "\\" & $szPath; Prepend the \\ we stripped earlier $szPath = ""; Set to null because the whole path was just the UNC server name Else $drive = "\\" & StringLeft($szPath, $pos - 1) ; Prepend the \\ we stripped earlier $szPath = StringTrimLeft($szPath, $pos - 1) EndIf EndIf ; Set the directory and file name if present Local $nPosForward = StringInStr($szPath, "/", 0, -1) Local $nPosBackward = StringInStr($szPath, "\", 0, -1) If $nPosForward >= $nPosBackward Then $pos = $nPosForward Else $pos = $nPosBackward EndIf $dir = StringLeft($szPath, $pos) $fname = StringRight($szPath, StringLen($szPath) - $pos) ; If $szDir wasn't set, then the whole path must just be a file, so set the filename If StringLen($dir) = 0 Then $fname = $szPath $pos = StringInStr($fname, ".", 0, -1) If $pos Then $ext = StringRight($fname, StringLen($fname) - ($pos - 1)) $fname = StringLeft($fname, $pos - 1) EndIf ; Set the strings and array to what we found $szDrive = $drive $szDir = $dir $szFName = $fname $szExt = $ext $array[1] = $drive $array[2] = $dir $array[3] = $fname $array[4] = $ext Return $array EndFunc ;==>_PathSplit
Moderators SmOke_N Posted October 7, 2008 Moderators Posted October 7, 2008 I used _PathSplit(), I meant to Say StringRegExp's ... however, now that we are on the subject... _PathSplit() does do much more and has been tested to be proficient. I have my own _PathSplit() function using nothing but RegEx that's much faster than that even ... but it's always safe to use something that's been used and trusted over the years. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
bluelamp Posted October 7, 2008 Posted October 7, 2008 I used _PathSplit(), I meant to Say StringRegExp's ... however, now that we are on the subject... _PathSplit() does do much more and has been tested to be proficient.It does things that sometimes aren´t neededI have my own _PathSplit() function using nothing but RegEx that's much faster than that even ... but it's always safe to use something that's been used and trusted over the years.Cdma1X asked for alternatives, I gave him one
Cdma1X Posted October 7, 2008 Author Posted October 7, 2008 I have my own _PathSplit() function using nothing but RegEx that's much faster than that even ... but it's always safe to use something that's been used and trusted over the years.SmOke_N, can i see your function?
Moderators SmOke_N Posted October 7, 2008 Moderators Posted October 7, 2008 (edited) SmOke_N, can i see your function?Func _SplitPath($s_path, ByRef $s_drive, ByRef $s_dir, ByRef $s_fname, ByRef $s_ext) If $s_path = "" Or StringInStr($s_path, '<>"|?*') Then Return SetError(1, 0, 0) Local $a_split = StringRegExp($s_path, "^(\w*:*)([\w\W]*[\\/]+)([\w\W]*)(\.[\w\W]*)\z", 1) If @error Then $a_split = StringRegExp($s_path, "^(\w*:*)([\w\W]*[\\/]+)([\w\W]*)(\.*[\w\W]*)\z", 1) If @error Then $a_split = StringRegExp($s_path, "^(\w*:*)\z", 1) If @error Then Return SetError(2, 0, 0) EndIf EndIf If UBound($a_split) = 1 Then $s_drive = $a_split[0] $s_dir = "" $s_fname = "" $s_ext = "" Else $s_drive = $a_split[0] $s_dir = $a_split[1] $s_fname = $a_split[2] $s_ext = $a_split[3] EndIf Local $avArray[5] = [$s_path, $s_drive, $s_dir, $s_fname, $s_ext] Return $avArray EndFunc Edit: Removed emoticons Edited October 7, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Cdma1X Posted October 7, 2008 Author Posted October 7, 2008 (edited) Thanks smOke_N, bluelamp Edited October 7, 2008 by Cdma1X
MrCreatoR Posted October 7, 2008 Posted October 7, 2008 (edited) I have one of my own to: _PathSplitByRegExp() Edited October 7, 2008 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Moderators SmOke_N Posted October 8, 2008 Moderators Posted October 8, 2008 I have one of my own to: _PathSplitByRegExp() That's funny, I forgot about that one ... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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