Results 1 to 4 of 4

Thread: [RESOLVED] how to get path location

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] how to get path location

    I used common dialog, How I can get the path location of my file?

    Code:
    dlgOpen.Filter = "Tin Files (*.tin)|*.tin"
    dlgOpen.ShowOpen
    InputFileTIN = dlgOpen.FileName
    MsgBox dlgOpen.FileName

  2. #2
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: how to get path location

    There's a few ways, ie using Split with "\" as the delimiter, APIs and:
    vb Code:
    1. Private Sub Form_Load()
    2.    MsgBox GetDirectoryFromPath("E:\VideoPaper\Videos\Atomic Kitten - Whole Again.mpg")
    3.    MsgBox GetFilenameFromPath("E:\VideoPaper\Videos\Atomic Kitten - Whole Again.mpg")
    4. End Sub
    5.  
    6. Public Function GetDirectoryFromPath(FullPath As String) As String
    7. 'Returns "E:\VideoPaper\Videos\".
    8.    GetDirectoryFromPath = Left(FullPath, InStrRev(FullPath, "\"))
    9. End Function
    10.  
    11. Public Function GetFilenameFromPath(FullPath As String) As String
    12. 'Returns "Atomic Kitten - Whole Again.mpg".
    13.    GetFilenameFromPath = Right(FullPath, Len(FullPath) - InStrRev(FullPath, "\"))
    14. End Function

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: how to get path location

    I use common dialog I got this messagebox "C:\Project\D.tin"

    dlgOpen.FileName

    i want to get this C:\Project\

  4. #4
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: how to get path location

    Using the code above:

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.    Dim strFN As String
    5.    
    6.    CommonDialog.Filter = "All Files (*.*)|*.*"
    7.    CommonDialog.ShowOpen
    8.    strFN = CommonDialog.FileName
    9.    MsgBox CommonDialog.FileName
    10.  
    11.    MsgBox GetDirectoryFromPath(CommonDialog.FileName)
    12. End Sub
    13.  
    14. Public Function GetDirectoryFromPath(FullPath As String) As String
    15.    GetDirectoryFromPath = Left(FullPath, InStrRev(FullPath, "\"))
    16. End Function

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