GetPathName




Function GetFileName(FileName As String) As String
'returns filename.ext from drive:\path\path\etc\filename.ext

Dim i As Integer
Dim tmp As String
For i = 1 To Len(FileName)
tmp = Right$(FileName, i)
If Left(tmp, 1) = "\" Then
GetFileName = Mid(tmp, 2)
Exit Function
End If
Next
GetFileName = ""
End Function

Function GetFileExtension(FileName As String, Optional LowerCase As Boolean = True) As String
' Returns last 4 chars of FileName. If lowercase = true (default) then it will be _

converted to small chars
If (LowerCase) Then
GetFileExtension = LCase(Right$(FileName, 4))
Else
GetFileExtension = Right$(FileName, 4)
End If
End Function

Function GetFilePath(FileName As String, Optional IncludeDrive As Boolean = True) As String
' returns path. drive can be excluded if needed

Dim i As Integer
Dim str As String
For i = 1 To Len(FileName)
str = Right$(FileName, i)
If Mid(str, 1, 1) = "\" Then
Dim iLenght As Integer
If (IncludeDrive) Then
iLenght = 1
Else
iLenght = 4
End If
GetFilePath = Mid$(FileName, iLenght, Len(FileName) - i) & "\"
Exit Function
End If
Next
GetFilePath = ""
End Function

Function GetDrive(FileName As String, Optional IncludeSlash As Boolean = False) As String
' returns lowercase drive ..

Dim iLenght As Integer
If (IncludeSlash) Then iLenght = 3 Else iLenght = 2
GetDrive = LCase(Left$(FileName, iLenght))
End Function











( getpathname.html )- by Paolo Puglisi - Modifica del 17/12/2023