• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

AutoIT Get File Extension, Filename, and Parent directory from Path

Status
Not open for further replies.

Nax

Leech
User
Joined
Oct 18, 2011
Messages
275
Reputation
0
Reaction score
115
Points
43
Credits
0
‎13 Years of Service‎
92%
Code:
>Func CompGetFileExt($Path,$Dot=True)
      ;by 1234hotmaster
   If StringLen($Path) < 4 Then Return -1
   $ret = StringSplit($Path,"\",2)
   If IsArray($ret) Then
       $ret = StringSplit($ret[uBound($ret)-1],".",2)
       If IsArray($ret) Then
           If $Dot Then
               $Dot = "."
           Else
               $Dot = ""
           EndIf
           Return $Dot & $ret[uBound($ret)-1]
       EndIf
   EndIf
   If @error Then Return -1
EndFunc
Code:
>Func CompGetFileName($Path)
      ;by 1234hotmaster
   If StringLen($Path) < 4 Then Return -1
   $ret = StringSplit($Path,"\",2)
   If IsArray($ret) Then
       Return $ret[uBound($ret)-1]
   EndIf
   If @error Then Return -1
EndFunc
Code:
>Func CompGetParentDir($Path,$EndSeparator=False)
      ;by 1234hotmaster
   If StringLen($Path) < 4 Then Return -1
   $ret = StringSplit($Path,"\",2)
   If IsArray($ret) Then
       Local $temp
       For $i = 0 To UBound($ret)-2
           $temp &= $ret[$i] & "\"
       Next
       If Not $EndSeparator Then $temp = StringTrimRight($temp,1)
       $ret=Chr(0)
       Return $temp
   EndIf
   If @error Then Return -1
EndFunc
 
Status
Not open for further replies.
Back
Top