Click to See Complete Forum and Search --> : File Name without extension
eng70640
Mar 13th, 2001, 10:27 AM
How can i obtain the name of a filename without its extension ? I mean if the filename is 1bitmap.jpg , then how can i obtain "1bitmap" of this particular filename ?
sFile = "Bitmap1.bmp"
sFile = Left(sFile, InStr(1, sFile, ".") - 1)
Print sFile
Lord Orwell
Mar 14th, 2001, 01:40 AM
of course that assumes that there IS an extension.
If there isn't you lose the entire file name. This small adjustment will fix that.
sFile = "Bitmap1.bmp"
pos = instrev(sFile, ".") -1
if pos > 0 then sFile = Left(sFile, InStRev(1, sFile, ".") - 1)
Print sFile
This also takes into account multiple dots in a file name.
Now all you have to worry about is a file name with a dot in it, but no extension.
Of course you could test for that with a dir$ statement when you are done.
if dir$(filename + ".*") = "" then error
sFile = "Bit.map1"
pos = instrev(sFile, ".") -1
if pos > 0 then sFile2 = Left(sFile, InStRev(1, sFile, ".") - 1)
if dir$(sfile2 + ".*") = "" then sfile2 = sfile1
print sfile2
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.