By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

Extract File Name From Path

P: n/a
Access 2000

I need to extract just the filename from a path.

Ex: path is- c:\MyApp\Sub\MyApp.exe

I need to capture just the file name regardless of the size of it's
name. For the above path it would be "MyApp.exe"

As Always
Any And All Help apreciated!
Dale

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Private Declare Function lstrcpyA _
Lib "kernel32" _
(ByVal RetVal As String, _
ByVal ptr As Long) _
As Long
Private Declare Function lstrlenA _
Lib "kernel32" _
(ByVal ptr As Any) _
As Long
Private Declare Function PathFindFileName _
Lib "shlwapi" _
Alias "PathFindFileNameA" _
(ByVal pPath As String) _
As Long
Private Function GetStrFromPtrA(ByVal lpszA As Long) As String
GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function
Public Function GetFilePart(ByVal sPath As String) As String
GetFilePart = GetStrFromPtrA(PathFindFileName(sPath))
End Function

Then when you use the function :
GetFilePart("C:\MyApp\Sub\MyApp.exe")
You get back:
MyApp.exe

mt****@yadtel.net wrote:
I need to extract just the filename from a path.
Ex: path is- c:\MyApp\Sub\MyApp.exe
I need to capture just the file name regardless of the size of it's
name. For the above path it would be "MyApp.exe"


Nov 13 '05 #2

P: n/a
In Immediate window:
?Dir ("c:\MyApp\Sub\MyApp.exe") will give you: MyApp.exe

(that is *if* MyApp.exe does exist in C:\MyApp\Sub . . .)

Arno R


<mt****@yadtel.net> schreef in bericht news:11**********************@g44g2000cwa.googlegr oups.com...
Access 2000

I need to extract just the filename from a path.

Ex: path is- c:\MyApp\Sub\MyApp.exe

I need to capture just the file name regardless of the size of it's
name. For the above path it would be "MyApp.exe"

As Always
Any And All Help apreciated!
Dale

Nov 13 '05 #3

P: n/a
Try in the bug windows:
?dir("c:\MyApp\Sub\MyApp.exe")

It should returns MyApp.exe
<mt****@yadtel.net> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Access 2000

I need to extract just the filename from a path.

Ex: path is- c:\MyApp\Sub\MyApp.exe

I need to capture just the file name regardless of the size of it's
name. For the above path it would be "MyApp.exe"

As Always
Any And All Help apreciated!
Dale

Nov 13 '05 #4

P: n/a

Arno R wrote:
In Immediate window:
?Dir ("c:\MyApp\Sub\MyApp.exe") will give you: MyApp.exe

(that is *if* MyApp.exe does exist in C:\MyApp\Sub . . .)

Arno R


Alternatively,

strFile = Right(strFull, InStr(RevStr(strFull), "\") - 1)

I'm not sure if A2K has a RevStr function so:

Public Function RevStr(strIn As String) As String
Dim lngI As Long

RevStr = ""
For lngI = 1 To Len(strIn)
RevStr = RevStr & Mid(strIn, Len(strIn) - lngI + 1, 1)
Next lngI
End Function

James A. Fortune

Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.