7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Sub Command1_Click()
Dim FilePath As String, S As String
Dim Arr() As String
FilePath = "F:\temp\del\SZOFFICE\projdocs\testDB\XXXX.DBF"
S = Right(FilePath, Len(FilePath) - InStrRev(FilePath, "\"))
Debug.Print S '结果是XXXX.DBF
Arr = Split(S, ".")
Debug.Print Arr(0) '结果是XXXX,去掉了扩展名
End Sub
Private Declare Sub PathStripPath Lib "shlwapi.dll" Alias "PathStripPathA" (ByVal pszPath As String)
Public Function GetFilenameFromPath(ByVal sFilePath As String, Optional ByVal bWithExtension As Boolean = True, Optional ByVal enmCase As VbStrConv = vbLowerCase) As String
'---------------------------------------------------------------------------------------
' Author : Ruturaaj
' Email : ruturajvpatki@hotmail.com
' Website : http://www.rcreations.co.nr
'=======================================================================================
' Procedure : GetFilenameFromPath
' Type : Function
' ReturnType : String
'=======================================================================================
' Purpose : Extract File name from given File path.
'---------------------------------------------------------------------------------------
On Error GoTo GetFilenameFromPath_Error
PathStripPath sFilePath
sFilePath = Mid$(sFilePath, 1, InStrRev(sFilePath, Chr$(0)) - 1)
If bWithExtension Then
GetFilenameFromPath = StrConv(sFilePath, enmCase)
Else
If InStr(sFilePath, ".") = 0 Then
GetFilenameFromPath = StrConv(sFilePath, enmCase)
Else
GetFilenameFromPath = StrConv(Mid$(sFilePath, 1, InStrRev(sFilePath, ".") - 1), enmCase)
End If
End If
'This will avoid empty error window to appear.
Exit Function
GetFilenameFromPath_Error:
'Show the Error Message with Error Number and its Description.
MsgBox "Error on Line " & Erl & vbCrLf & vbCrLf & Err.Description, vbCritical, "GetFilenameFromPath Function"
'Safe Exit from GetFilenameFromPath Function
Exit Function
End Function
Private Sub Command1_Click()
Dim strP As String
Dim intP As Integer
Dim strA() As String
Dim strB() As String
On Error GoTo errSub
strP = "F:\temp\del\SZOFFICE\projdocs\testDB\XXXX.DBF"
strA = Split(strP, "\")
strB = Split(strA(UBound(strA)), ".")
Debug.Print strB(0)
Exit Sub
errSub:
End Sub
private function GetIt(s as string) as string
dim P as long
p=instrrev(s,"\")
if p>0 then
getit=right(s,p+1)
end if
end function