Results 1 to 4 of 4

Thread: ExtractFileName

  1. #1
    Join Date
    May 2004
    Posts
    5

    Unanswered: ExtractFileName

    Hello!

    I am looking for a function to extract a filename from a filepath.
    Ex. Input: C:\hello\hello.txt
    Output: hello.txt

    Sincerly Richard

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Unfortunately I don't have MS Access on the computer I'm currently using, so I'm going to assume the REVERSE() function works the way I assume it would:
    Code:
    'assume Path is a string variable containing the path and file name
    
    Path = Reverse(Path)
    
    MsgBox Reverse(Left(path, InStr("\", Path, 0) - 1))
    Again, I apologize that I'm not able to test the code, but hopefully you can get enough of an idea to make a workable solution.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Nov 2003
    Posts
    1,487
    Function: GetFileNameFromPath



    Code:
    Public Function GetFileNameFromPath (PathStrg As String) As String
    	Dim a$, b$, c$, i As Integer
    	On Error Resume Next
    	b$=
    	For i = len(PathStrg) To 1 Step -1
    	   a$ = Mid$(PathStrg, i, 1)
    	   If a$ = \ Then Exit For
    	   b$ = b$ & a$
    	Next i
    	If b$ =  Or Err <> 0 Then GetFileNameFromPath = : Exit Function
    	For i = Len(b$) To 1 Step -1
    		a$ = Mid$(b$, i, 1)
    		GetFileNameFromPath  = GetFileNameFromPath & a$
    	Next i
    	GetFileNameFromPath  = Trim(GetFileNameFromPath)
    End Function


    USAGE:

    MsgBox GetFileNameFromPath(ProvidedPathString)



  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Finally at a computer with Access!!
    Code:
    Public Function ExtractFileName(s As String) As String
    s = StrReverse(s)
    s = StrReverse(Left(s, InStr(1, s, "\") - 1))
    ExtractFileName = s
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •