Sign in to follow this  
Followers 0
themax90

Suggested UDF : _ExtractName

3 posts in this topic

#1 ·  Posted (edited)

Here is my UDF that will extract the name of a path or url for copying, downloading, etc....

You can use like this:

$URL = "http://www.google.com/index.htm"
InetGet($URL, "C:\" & _ExtractName($URL), 1, 1)

Hope you like enough to add into AutoIt's next beta!

;===============================================================================
; Function Name:      _ExtractName()
; Description:      Extracts a filename from a url or path for downloading/copying etc....
;                     Sets @Error to -1 if error occurs, otherwise @Error = 0
;                     Returns:
;                       %String% = Could Extract Filename (Success)
;                       0 = No filename found (Failure)
;                       -1 = Invalid String/Path/URL (Failure)
;                       -2 = Unknown Error (Failure)
;
; Author(s):          Max Gardner (AutoIt Smith) <king.of.all@comcast.net>
;===============================================================================
Func _ExtractName($String)
    Local $Path, $URL, $Filename, $FileCheck
    $Path = StringSplit($String, "\", 1)
    $URL = StringSplit($String, "/", 1)
    Select
        Case $Path[0] >= 2
       ; Extract From Path
            SetError(0)
            $Filename = $Path[$Path[0]]
            $FileCheck = StringSplit($Filename, ".", 1)
            If $FileCheck[0] <= 1 Then
                SetError(-1)
                Return 0
            EndIf
            SetError(0)
            Return $Filename
        Case $URL[0] >= 2
       ; Extract From URL
            SetError(0)
            $Filename = $URL[$URL[0]]
            $FileCheck = StringSplit($Filename, ".", 1)
            If $FileCheck[0] <= 1 Then
                SetError(-1)
                Return 0
            EndIf
            SetError(0)
            Return $Filename
        Case Else
       ; Invalid Path/URL
            SetError(-1)
            Return -1
    EndSelect
    SetError(-1)
    Return -2
EndFunc ;==>_ExtractName

AutoIt Smith

P.S. FINE LXP I will fix it, even though this is basically useless and no body will use it.

Fixed : Dim to Local

Edited by AutoIt Smith

Share this post


Link to post
Share on other sites



Nobodys even posting, do you all not like this?

Share this post


Link to post
Share on other sites

Too simple. I already have a UDF like this one.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0