Solved

Get the name of a file of a string containing the full path name

Posted on 2003-11-26
2
265 Views
Last Modified: 2010-05-01
I have the full path name in a string variable, eg.:
strFileName = "C:\temp\filename.txt"

How do I extract only the filename from the string above, in this case that would be "filename" only?
0
Comment
Question by:8831
  • 2
2 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9829849
   Dim strFullPathToFileName As String
    Dim strPath As String
    Dim strFileName As String
    Dim backslashPos As Integer
   
    strFullPathToFileName = "C:\temp\filename.txt"
    backslashPos = InStrRev(strFullPathToFileName, "\")
    If backslashPos > 0 Then
        strPath = Left(strFullPathToFileName, backslashPos)
        strFileName = Mid(strFullPathToFileName, backslashPos + 1)
    Else
        strPath = ""
        strFileName = strFullPathToFileName
    End If
   
    Debug.Print strPath
    Debug.Print strFileName

Regards,

Idle_Mind
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 9829852
If you want the filename without the extension then do the exact same thing using strFileName, but search for "." instead of "\".

Idle_Mind
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question