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

Extracting the file name ONLY from path

Status
Not open for further replies.

ReportSmithing

Programmer
Apr 15, 2005
41
US
I'm hoping someone can help me out with this problem. I need to extract the file name from a path - I've already been able to strip away up to the file name but I need to strip away the file extension also.

Here's what I have so far...

Dim i As Long
fname = ActiveTitle()
FileExt = Right$(ActiveTitle(), Len(ActiveTitle()) - InStr(ActiveTitle(), "."))

On Error Resume Next
For i = Len(fname) To 1 Step -1
If Mid(fname, i, 1) = "\" Then
Exit For
End If
Next i
GetFileName = Trim(Mid(fname, i + 1))

This works fine, but I still need the file extension removed. Heres the catch: I can't use RevInStr to do this since I'm working on an older application.

Thanks for you help.
 
But surely that problem is caused by the fact that we won't have done some explicit clean up (e.g. Close) that a Recordset object requires, - and even explicitly setting the recordset to Nothing under the same conditions causes the same problem, doesn't it? So in that case the issue is the design of the Recordset class, and its Termination code, rather than anything else. Unless I'm misunderstanding you.
 
I agree with you that the issue should be in the Termination code of the class.
 
There is no explicit DestroyObject method. All objects are implicitly destroyed when appropriately terminated and all references to them have been destroyed. Many problems are caused by people not understanding the nature of objects and pointers and not setting to nothing pointers which they have previously set to something (possibly pointers to subordinate objects).

In this case no pointer is set so no pointer can be released. The object requires no explicit termination so should be (and AFAIK is) destroyed on completion of the statement.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Could all be resolved by using the worksheet formula and picking up the text from the cell anyway ;-)

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top