Announcement

Collapse
No announcement yet.

File extensions?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File extensions?

    Is there a method for determing if a filespec holds an extension?

    In the old DOS days of 8:3 filenames it was fairly straight forward - look for the "." - not so simple with long names. For example you may find a valid filespec of:

    Code:
    filespec = "MyValidFile.Name.txt.dt"
    In this example I would regard the ".dt" as the file extension.

    If there's no easy or established method, I'll develop my own but I thought this issue must have been "solved" before.


    Pat

  • #2
    Look for the dot starting at the end and working backwards?
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      With the latest compiler you can use PATHNAME$

      http://www.powerbasic.com/support/help/pbcc/pathname$_function.htm

      Comment


      • #4
        This has always worked for me:

        Code:
        MID$(Pathname$, INSTR(-1, Pathname$, "."))
        Jeff Blakeney

        Comment


        • #5
          Paul's suggestion with PB 9/5 is the new way:
          Code:
          filespec = "MyValidFile.Name.txt.dt"
          PATHNAME$(EXTN,  filespec) 'returns ".dt"

          Comment


          • #6
            Code:
            DECLARE FUNCTION PathFindExtension LIB "SHLWAPI.DLL" ALIAS "PathFindExtensionA" _
                (pszPath AS ASCIIZ) AS DWORD
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              I haven't been using PBWin 9 for very long and I hadn't come across the PATHNAME$ function but I'm not sure I'll be using it. Of the four forms it can take, all but one can be replaced with a single line of code. The one that takes two lines of code is the one for getting the filename without an extension and I can see little use for that. Besides, the way I do it can all be replaced with a macro or function if desired. And by creating your own macro or function, you can also add the ability to pull out the drive as well as get the number of directories in the path and pull out each individual directory name which you can't do with the PATHNAME$ command.
              Jeff Blakeney

              Comment

              Working...
              X