Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • +4 Selecting a different directory changes the application's current directory.

Example

...

Code Block
languagevb
 Dim fullName As String
 

...

fullName = GetFilePath(,"txt",Project.Path,"Select Text File")


Advanced Examples

The following code shows the simplest way I know of to get the file name and the path to the file from the GetFilePath() output.

Code Block
languagevb
Sub main
 	Dim fullName As String
        Dim fileName As String
        Dim filePath As String
        Dim temp() As String
        Dim n As Integer
        Dim i As Integer

        fullName = GetFilePath(,"txt",Project.Path,"Select Text File")
        temp = Split(fullName,"\")
        n = UBound(temp)

        fileName = temp(n)

        filePath = ""
        For i=0 To n-1
                filePath = filePath + temp(i) + "\"
        Next i

        Debug.Print fileName
        Debug.Print filePath
End Sub 

 

 

Another way of doing this

 

Code Block
languagevb
' Code Module
Sub Main
    fn$ = GetFilePath$(,"xml",,"Choose XML File") 'gets full path and filename
    If fn$="" Then Exit Sub 'Cancel was pressed, exit the sub
    fname$ = Mid$(fn$,InStrRev(fn$,"\")+1) 'gets file name with extension
    fname_root$ = Left(fname$,InStr(1,fname$,".")-1) 'gets filename without extension
    tks = Split(fn$,fname$)
    fpath$ = tks(0) 'gets path to filename

End Sub