Solved

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

Posted on 2003-11-26
2
261 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
Comment Utility
   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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now