Public Function GetFileName(ByVal FilePathFileName As String) As String '获取文件名 aaa.txt On Error Resume Next Dim i As Integer, J As Integer i = Len(FilePathFileName) J = InStrRev(FilePathFileName, "/") MsgBox(J) GetFileName = Mid(FilePathFileName, J + 1, i) End Function '获取两个字符串中间的字符串 Private Shared Function SearchMidString(ByVal s As String, ByVal s1 As String, ByVal s2 As String) As String '获取搜索到的数目 Dim n1 As Integer, n2 As Integer n1 = s.IndexOf(s1, 0) + s1.Length '开始位置 n2 = s.IndexOf(s2, n1) '结束位置 Return s.Substring(n1, n2 - n1) '取搜索的条数,用结束的位置-开始的位置,并返回 End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'MsgBox(GetFileName("/dir1001/aaa.txt"))获取文件名字 Dim cc As String '定义字符串 Dim ee As String '定义路径文件夹数组 Dim ff As Integer '定义有多个个目录名字 Dim ii As Integer '循环查找目录名字 Dim jj As Integer '循环建立目录 cc = "/dir1001/sdfsdf/aaa.txt" ff = 0 For ii = 0 To Len(cc) If Len(cc) <= 0 Then Else If (cc.Split("/").Length - 1) >= 2 Then MsgBox(SearchMidString(cc, "/", "/")) '截取两个字符之间的字符串 Else Exit For End If 'MsgBox(InStr(1, cc, "/")) '查找字符中第一个/出现的位置 'MsgBox(Mid(cc, (InStr(1, cc, "/")) + 1)) '截取第二个字符到最后的字符 ff = ff + 1 cc = (Mid(cc, (InStr(1, cc, "/")) + 1)) End If Next ii End Sub |
转载请注明:vs2010» 读取文件路径的文件夹名字
标签: