#include <Array.au3> ;Only for example $Path = "c:\test\my folder\file.zip" $PathArr = _PathSplitByRegExp($Path) If IsArray($PathArr) Then _ArrayDisplay($PathArr, "Demo of _PathSplitRegExp()") ElseIf $PathArr = $Path Then MsgBox(64, "Demo of _PathSplitRegExp()", $PathArr) Else MsgBox(48, "Error", "The path is not correct") EndIf ;=============================================================================== ; Function Name: _PathSplitByRegExp() ; Description: Split the path to 8 elements. ; Parameter(s): $sPath - Path to split. ; Requirement(s): AutoIt 3.2.2.0. ; Return Value(s): On seccess - Array $aRetArray that contain 8 elements: ; $aRetArray[0] = Full path ($sPath) ; $aRetArray[1] = Drive letter ; $aRetArray[2] = Path without FileName and extension ; $aRetArray[3] = Full path without File Extension ; $aRetArray[4] = Full path without drive letter ; $aRetArray[5] = FileName and extension ; $aRetArray[6] = Just Filename ; $aRetArray[7] = Just Extension of a file ; ; On failure - If $sPath not include correct path (the path is not splitable), ; then $sPath returned. ; If $sPath not include needed delimiters, or it's emty, ; then @error set to 1, and returned -1. ; ; Note(s): The path can include backslash as well (exmp: C:/test/test.zip). ; ; Author(s): G.Sandler a.k.a CreatoR (MsCreatoR) - Thanks to amel27 for help with RegExp ;=============================================================================== Func _PathSplitByRegExp($sPath) If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1) Local $aRetArray[8], $pDelim = "" If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\" If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//" If $pDelim = "" Then $pDelim = "/" If Not StringInStr($sPath, $pDelim) Then Return $sPath If $pDelim = "\" Then $pDelim &= "\" $aRetArray[0] = $sPath ;Full path $aRetArray[1] = StringRegExpReplace($sPath, $pDelim & '.*', $pDelim) ;Drive letter $aRetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '') ;Path without FileName and extension $aRetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '') ;Full path without File Extension $aRetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & ')', '') ;Full path without drive letter $aRetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '') ;FileName and extension $aRetArray[6] = StringRegExpReplace($sPath, '.*' & $pDelim & '|\.[^.]*$', '') ;Just Filename $aRetArray[7] = StringRegExpReplace($sPath, '^.*\.', '') ;Just Extension of a file Return $aRetArray EndFunc |