Seperate file extension from file name

M

mpfohl

In my code I have the user select a file to be copied. It then
prompts the user for the new name of the file. The file is then saved
as a string (e.g. "MyFileName.txt")

I need to seperate the file name from the file's extension so I can
have "MyFileName" and know that it's extension is ".txt"

I think I can just use Left(myStringName, Len(myStringName) - 4)

However:
a) am i write in assuming that all file extensions are 3 charactors
plus a period?
b) what's the easiest way to check if the user provide file name
includes a valid extension so i know whether to reprompt the user to
include it (or create code to include it myself)?

Thanks
 
A

Allen Browne

Use InstrRev() to find the last dot in the file name.

Extensions are not all 3 characters any more. Example:
somefile.html
 
Top