vb.net从文件路径中获取文件名

2022-07-27 科技 488阅读
获取方法,参考实例如下:
'获取路径名各部分: 如: c:\dir1001\aaa.txt
'获取路径路径 c:\dir1001\
Public Function GetFileName(FilePathFileName As String) As String '获取文件名 aaa.txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
GetFileName Mid(FilePathFileName, J + 1, i)
End Function
''获取路径路径 c:\dir1001\
Public Function GetFilePath(FilePathFileName As String) As String '获取路径路径 c:\dir1001\
On Error Resume Next
Dim J As Integer
J InStrRev(FilePathFileName, "\")
GetFilePath Mid(FilePathFileName, 1, J)
End Function
'获取文件名但不包括扩展名 aaa
Public Function GetFileNameNoExt(FilePathFileName As String) As String '获取文件名但不包括扩展名 aaa
On Error Resume Next
Dim i As Integer, J As Integer, k As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
k InStrRev(FilePathFileName, ".")
If k 0 Then
GetFileNameNoExt Mid(FilePathFileName, J + 1, i - J)
Else
GetFileNameNoExt Mid(FilePathFileName, J + 1, k - J - 1)
End If

End Function

'===== '获取扩展名 .txt
Public Function GetFileExtName(FilePathFileName As String) As String '获取扩展名 .txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, ".")
If J 0 Then
GetFileExtName ".txt"
Else
GetFileExtName Mid(FilePathFileName, J, i)
End If
End Function
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com