Parsing a network path

K

kidkosmo

Hi, Gang,

I am looking for help in parsing out a file name from a file path.
I'm using the GetOpenFile api for users to choose the file path, which
is what I'm using for a web form to upload the file to a wiki page;
however, I also want to extract just the file name. So, in the
example below, I want to return a string value of just "History.mdb"
and save that in my table (after the upload, I no longer need the
entire path).

C:\Documents and Settings\me\My Documents\History.mdb

I have tried using the following formula: strfile = Right$
(strFilename, Len(strFilename) - InStr(1, strFilename, "\") - 1).
Because the delimiter of "\" appears multiple times, I don't get what
I'm looking for.

I appreciate your help!
 
K

kidkosmo

Hi, Gang,

I am looking for help in parsing out a file name from a file path.
I'm using the GetOpenFile api for users to choose the file path, which
is what I'm using for a web form to upload the file to a wiki page;
however, I also want to extract just the file name.  So, in the
example below, I want to return a string value of just "History.mdb"
and save that in my table (after the upload, I no longer need the
entire path).

C:\Documents and Settings\me\My Documents\History.mdb

I have tried using the following formula: strfile = Right$
(strFilename, Len(strFilename) - InStr(1, strFilename, "\") - 1).
Because the delimiter of "\" appears multiple times, I don't get what
I'm looking for.

I appreciate your help!



Nevermind...I just discovered the InStrRev function.

strfile = Right$(strFilename, Len(strFilename) -
InStrRev(strFilename, "\"))

Seems to give me what I need.
 
D

Daryl S

Kidkosmo -

Try InStrRev instead of InStr. InStrRev searched from the end of the string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top