Solved

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

Posted on 2003-11-26
2
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 86

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 86

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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