Function GetFileName(FilePath As String) As String
Dim dlmPos As Long
Dim bInclude As Boolean
dlmPos = InStrRev(FilePath, "\")
bInclude = InStrRev(FilePath, ".") > dlmPos
If dlmPos > 0 Then
If bInclude Then
GetFileName = Right$(FilePath, Len(FilePath) - dlmPos)
Exit Function
End If
End If
GetFileName = FilePath
End Function
Public Sub Sample_1()
Msgbox Dir(FilePath)
End Sub
|
Public Function GetFolderPath(FilePath As String) As String
Dim dlmPos As Long
Dim FileName As String
Dim bInclude As Boolean
dlmPos = InStrRev(FilePath, "\")
bInclude = InStrRev(FilePath, ".") > dlmPos
If dlmPos > 0 Then
If bInclude Then
FileName = Right$(FilePath, Len(FilePath) - dlmPos)
GetFolderPath = Left(FilePath, Len(FilePath) - Len(FileName))
Exit Function
End If
End If
GetFolderPath = FilePath
End Function
Public Sub Sample_2()
Msgbox Replace(FilePath, Dir(FilePath), "")
End Sub
|