Announcement

Collapse
No announcement yet.

GetFullPath, how to use it?

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

  • GetFullPath, how to use it?

    In the PBDLL example-directory I've found a routine to convert a so called long path (e.g. "c:\program files") into a DOS-path: c:\progra~1.
    Is there an opposite way? I've tried to use the GetFullPath API for this purpose, but it only returns the original short pathname as the new name.
    (BTW: the shortpath-routine can be found in "\samples\common\common.bas")

    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

  • #2
    Hello Egbert,
    Following converts long name into short and into long again.
    Code:
    #Include "win32api.inc"
    
    Function PbMain() As Long
      Local lRet&, lzStr As Asciiz * %MAX_PATH, lWIN32_FD As WIN32_FIND_DATA
      Print "Full name at start:" ;Command$
      GetShortPathName Command$, lZstr, SizeOf (lzStr)
      Print "8.3 filename      :" ; lzStr
      lRet = FindFirstFile (lzStr, lWIN32_FD)
      Print "Full path again   :" ; lWin32_Fd.cFileName
      CloseHandle lRet
    End Function
    Can even be shorter:

    Print Dir$(Command$)
    '(command$ = short 8.3 name)
    ------------------
    Peter.
    mailto[email protected][email protected]</A>

    [This message has been edited by Peter Lameijn (edited December 04, 2000).]
    Regards,
    Peter

    Comment


    • #3
      GetFullPathName() is just a concatentation function, since it does not convert 8.3 to LFN's.

      If it's just the filename you want as a LFN then DIR$() will return that, but not the path. For that you need to use the GetLongPathName() function, but it is apparently only available in Win98 or later.




      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        There is also API GetLongPathName (98/2000 only)


        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          I ran into the same problem when opening a
          file through the explorer into my app.
          The residing directory is where the person
          clicked the file that is passed onto command$, I then use a
          curdir$ to return the longfilename with a dir$.
          like this:

          FUNCTION longfilename(BYVAL shortfilename AS STRING) AS STRING
          LOCAL lfilenm AS STRING
          lfilenm=DIR$(shortfilename)
          IF lfilenm<>"" THEN
          FUNCTION=CURDIR$+"\"+lfilenm
          END IF
          END FUNCTION

          (var shortfilename can be read as command$ or as @lpszCmdLine)

          When enclosing something like a chdir you could do the same for
          directories were you're not residing.



          One of the roads that lead to Rome that works great for me !!

          kuif aka Herman Kieskamp


          ------------------
          You gotta run, and don't loop back.

          Comment


          • #6
            Thanks for your contributions, but unfort. no help for me. I think there is no way to do this in W95, indeed.
            To 'Kuif': Herman, I need this function for directory names, such as Program Files versus Progra~1, not for
            filenames.

            ------------------
            mailto:[email protected][email protected]</A>
            www.basicguru.com/zijlema/

            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
            http://zijlema.basicguru.eu
            *** Opinions expressed here are not necessarily untrue ***

            Comment


            • #7
              The same technique works for directory names, which are really just filenames
              themselves. Just remember to include the directory attribute (16) in your
              FindFirstFile or DIR$ specification.

              ------------------
              Tom Hanlin
              PowerBASIC Staff

              Comment


              • #8
                Example with Dir$ on full long path:
                Code:
                '-------------------------------------------------------------------------------
                ' LongPathName
                '-------------------------------------------------------------------------------
                $Compile Exe
                
                Function  LongPathName (ShortFileName As String) Export As String
                  Local lIn As String, lOut As String, lRet As Long, lDir As String, lRep As String
                  lIn = ShortFileName
                  lOut = lIn
                  While -1
                    lRet = Instr(-1, lIn, "\")
                    lDir = Dir$(LIn,16)
                    If (lDir <> "") And (Len(lIn) > 2) Then
                      lRep = Mid$ (lIn,lRet +1)
                      Replace lRep With lDir In lOut
                    Else
                      Function = lOut
                      Exit Function
                    End If
                    lIn = Left$(lIn, lRet -1)
                  Wend
                End Function
                
                Function WinMain (ByVal CurInst As Long, _
                                  ByVal PrvInst As Long, _
                                  CmdLine As Asciiz Ptr, _
                                  ByVal CmdShow As Long) Export As Long
                'Example used: c:\program files\common files\microsoft shared\verylongname.tst
                  MsgBox LongPathName ("c:\progra~1\common~1\micros~1\verylo~1.tst")
                End Function
                ------------------
                Peter.
                mailto[email protected][email protected]</A>
                Regards,
                Peter

                Comment

                Working...
                X