Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query language to give me the file name from the end of a path

Status
Not open for further replies.

keun

Technical User
Jul 15, 2005
262
US
I have document paths, including file name, in a PATH field:

MyDocs\Pictures\honeymoonIsOVer.jpg
MyDocs\WorkStuff\Accounting\Quarterly\FakeInvoices.xls
MyDocs\HideFromTheBoss\NotPron\specs.jpg


So, the folder structure will vary, but the text I am looking for is everything after the last backslash. This gets me what I want in Excel:


=RIGHT(A2,LEN(A2)-FIND(CHAR(1),SUBSTITUTE(A2,".",CHAR(1),LEN(A2)-LEN(SUBSTITUTE(A2,".","")))))
 
Sorry, what's my problem... that function gets me the extension. Of course, I need the file name, including extension. My bad!

thanks all
 
Code:
Public Function getFileName(varPath As Variant) As String
  If Not IsNull(varPath) Then
    getFileName = Mid(varPath, InStrRev(varPath, "\") + 1)
  End If
End Function

Code:
SELECT tblOne.strPath, getFileName([strPath]) AS FileName
FROM tblOne;

[tt]
strPath FileName
MyDocs\WorkStuff\Accounting\Quarterly\FakeInvoices.xls FakeInvoices.xls
MyDocs\Pictures\honeymoonIsOVer.jpg honeymoonIsOVer.jpg
MyDocs\HideFromTheBoss\NotPron\specs.jpg specs.jpg
[/tt]
 
Thanks. I used this last week, but took a while to get back here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top