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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting File name... 2

Status
Not open for further replies.

Kib

Programmer
May 17, 2001
58
US
If I have a string containing the path and file name
ex:
"c:\windows\desktop\mh.xls"
how can I trim off the path and just return the file name
"mh.xls"
?
Thanks
 
Use the INSTR() function to look for the last "\" (I believe you can search from the right by using a negative number) and then get the characters from the right of that last slash by using the RIGHT function. Look these two up in help for more info... Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
If you are using Ms. Acceess 2K, use the SPLIT function. the last element of the array will be the file name.

If you have an earlier ver, there is a routine "basSplit" (and some other similar ones) posted in various threads which will also do this.

If you do not have the patience to wait for the search enging to be returned to service, Terry's suggestion to use InStr and Right is an appropiate way to do it, although I do not recall ... "(I believe you can search from the right by using a negative number) .


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Thanks both of you.
There is actually a function called InStrRev() That will search from the end of the string.
Thanks for helping.
Kib
 
Yes, but it is ver 2K. If you have that, Split is somewhat easier to use to get the filename seperated from the path.

Another really easy one is to use the "Dir()" function)

e.g.

? Dir("c:\windows\desktop\mh.xls")
mh.xls

further, this permits some proof that the file exists, since if it doesn't, dir will return an empty string!



MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top