CodeItBetter Programming Another VB Programming Blog

How to Retrieve the Filepath from a Path

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'File/Folder Handling - How to Retrieve the Filepath from a Path
Option Explicit
 
Public Function GetFilePath(ByVal FilePath As String) As String
    Dim slashLocation As Integer
 
    On Error GoTo GetFilePath_Error
 
    If Len(FilePath) = 0 Then
        GetFilePath = ""
        Exit Function
    End If
 
    'Find the last \ in the path
    slashLocation = InStrRev(FilePath, "\")
 
    If slashLocation = 0 Then
        GetFilePath = ""
    Else
        GetFilePath = Mid$(FilePath, 1, slashLocation)
    End If
 
ExitHere:
    On Error GoTo 0
    Exit Function
 
GetFilePath_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetFilePath of Form Form1"
End Function

Related posts:

  1. How to Retrieve the File Name from a Path
  2. How to Read a file and add each line to an array of strings
  3. How to write a string array to a text file
  4. How to Open a File and return the File Number
  5. How to Close a File for a given File Number
  6. How to Retrieve the FilePath from process identified using a hwnd
  7. How to Return the path of a given full path to a file
  8. How to Check whether the given Path is Writeable
  9. How to retrieve the full long path name from short path (MS Dos format)
  10. How to use Net send to send message from one system to another system in Windows Network.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.