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

stripping the file extension 1

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
I got this nice little function via a google search. But it is doing the exact opposite of what I need. It is taking a filename (Ex: test.jpg) and returning the extension and preceding period (Ex: .jpg). I need to rework this to only return the filename, everything before the period and extension (Ex: test). Can anyone help me do this?
Code:
function StripFileExt(strFileName)
	if strFileName = "" Then Exit function
	if InStr(1, strFileName, ".") = 0 Then Exit function
	StripFileExt = Right(strFileName, Len(strFileName) - InStrRev(strFileName, ".") + 1)
End function
 
Just change the Right to Left and adjust the counter to count from before the . instead of after:
Code:
function StripFileExt(strFileName)
        if strFileName = "" Then Exit function
        if InStr(1, strFileName, ".") = 0 Then Exit function
        StripFileExt = [COLOR=red]left[/color](strFileName, InStrRev(strFileName, ".")[COLOR=red] - 1[/color])
End function

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top