INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

General Information

Finding FileName in FilePath by MikeC14081972
Posted: 17 Mar 08

A question I get asked a lot is how to extract a filename from a full filepath.

Whilst you can use InStr and loop through the filepath I have found it much easier to start at the other end of the path and work backwards

i.e. Passing in a FullPath of "C:\MyDocuments\Test.txt" to the below function will extract a filename of Test.txt

CODE

Function FileName (FullPath as string)

Dim FileName as string
Dim Pos as Integer

Pos = InStrRev (FullPath,"\",,vbTextCompare)
FileName = Mid(FullPath,Pos +1)

Debug.Print FileName

Exit Function

The code starts at the end of the string and Pos in the position of the first "\" moving backwards.

Using the Mid function you can then extract the filename by starting at position pos+1

Back to Microsoft: Access Forms FAQ Index
Back to Microsoft: Access Forms Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close