VB 如何截取文件名

来源:百度知道 编辑:UC知道 时间:2024/05/10 16:42:29
VB中截取一个路径中的文件名名手扩展名,如下面的应该如何截取:

C:\Documents and Settings\千面の郎君\桌面\3.exe

我只想得到“3.exe”其它的不要
你这个是从百度搜到的吧,我试过了没用的。我的不是网址截取,是文件路径中的文件名截取.
请给出详细代码。谢谢

绝对原创,除了msdn了,你别忘记加在运行库,哎呀

vb[工程]菜单,选择[引用],选择Microsoft Scripting runtime(scrrun.dll)
代码:
Private Sub Command1_Click()
Dim fso As New FileSystemObject
MsgBox fso.GetFileName("C:\Documents and Settings\千面の郎君\桌面\3.exe")
End Sub
显示:
3.exe

在C#里面有个system.io.path.GetExtension("");可以取出后缀名,VB里面也应用有吧.

dir(\"C:\\Documents and Settings\\千面の郎君\\桌面\\3.exe \")

就行了,dir是VB内部函数,

str = "C:\Documents and Settings\千面の郎君\桌面\3.exe "

s = split(str,"\")
msgbox ubound(s)

'这是我自己写的获得文件名的函数.
Function GetFileName(Path As String) As String
Dim Fi As Long
'If Dir(Path) = Empty Or Len(Path) = 0 Then Exit Function '判断路径是否正确
For Fi = Len(Path) To 1 Step -1
If Mid(Path, Fi, 1) = "\" Then
GetFileName = Mid(Path, Fi + 1)
Exit For
End If<