Results 1 to 3 of 3

Thread: File Name without extension

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    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 ?

  2. #2
    Guest
    Code:
    sFile = "Bitmap1.bmp"
    sFile = Left(sFile, InStr(1, sFile, ".") - 1)
    Print sFile

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width