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

Filename without extension 1

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
I have a variable called f and defined as file.
Now I display the filename using f.Name (picture.tif)
I want to display only the filename without the extension (picture).
Is this possible ?
 
Left(f.Name, InStrRev(f.Name, ".") - 1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, Thanks for your quick response.
This is the work-around, I thought maybe there was a command like f.SmallName or something like that.

I will use this option.

Thanks again
 
This is nice, strongm!
Didn't know about that method.
[thumbsup2]


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 



I've often used Split for this...
Code:
=FName = Split(f.name, ".")(0)


Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yeah, that would of course also do it.
Alas, despite my strong "discouragement" of such habits, some of our project managers occasionally put dots in the folder name (e.g. date)!! [nosmiley]
It's a major drawback for any such use.
GetBaseName does not get confused by this, neither does the InStrRev way, neither does
Code:
NoExt=left(f.name,len(f.name)-4)

The latter however will get confused if there is such a nice thing as a "Thumbs.db" file in that folder, as it only has a 2 char extension... [rolleyes]
[flush3]

So, both GetBaseName and InstrRev are my preferred.

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 


MakeItSoe,

In that case...
Code:
Function NameSansExtension(sName As String) As String
    Dim a, i As Integer
    a = Split(sName, ".")
    NameSansExtension = a(UBound(a) - 1)
    If UBound(a) > 1 Then
        For i = UBound(a) - 2 To 0 Step -1
              NameSansExtension = a(i) & "." & NameSansExtension
        Next
    End If
End Function

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Why make it simple when you can make it overcomplicated ? <grin>
 


Absolutely! ;-)

Because its there!

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip are you seriously suggesting that all that yaddayaddayadda is better than:

fso.GetBaseName(f.Path)

???? Surely you jest.


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top