Get File Name from Path

S

Scott

How can I get just the filename mypic1.jpg from below path? The path can
change to other sub folders, so I'd like to get the text after the last "\".

PATH

C:\data\access\mypic1.jpg
 
C

Crystal

Hi Scott,

you can do a reverse search for \
and then take the RIGHT characters from the string for the
filename

dim mPos as integer, mFilename as string
mPos = instrRev(FilePath_variable,"\")

mFilename = right(FilePath_variable,
len(FilePath_variable)-mPos)


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
C

Crystal

Hi Duane,

You are so clever!

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
D

Duane Hookom

Your solution is more robust since my solution requires the file to exist.
If there is no file of that spec, the Dir() won't return any value.
 
C

Crystal

Hi Duane,

Thanks ... did I just get a consolation prize ;)

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
D

Duane Hookom

No, I think you get the Gold and I get the Silver since I took a short cut
that might lead to a tree or rock.
 
S

Scott

thx.

Crystal said:
Hi Scott,

you can do a reverse search for \
and then take the RIGHT characters from the string for the filename

dim mPos as integer, mFilename as string
mPos = instrRev(FilePath_variable,"\")

mFilename = right(FilePath_variable, len(FilePath_variable)-mPos)


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
C

Crystal

you are funny, Duane ;) and you must be a skiier too ;)

I am happy you posted that -- it is something else to think
about...

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
C

Crystal

you're welcome, Scott ;) happy to help

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
Top