欢迎来到路由器窝!

读取文件路径的文件夹名字

浏览次数:

作者: 路由器窝

信息来源:

更新日期: 2016-12-08 13:38

文章简介

Public Function GetFileName(ByVal FilePathFileName As String) As String 获取文件名 aaa.txt On Error Resume Next Dim i As Integer, J

  • 正文开始
  • 相关文章
  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» 读取文件路径的文件夹名字

标签:
上一页:截取两个字符中间的字符串
下一页:软件安装包制作(Advanced Installer)11.6.0 最新破解版
最近更新作品
VB.net基础:如何获得并显示网上图片
更新时间:2020-07-02

186人已经看过了!

获取网站代码
更新时间:2019-09-21

179人已经看过了!

vb.net 正则表达式 取 html代码中的A标签的 href 链接
更新时间:2019-09-21

321人已经看过了!

VB.NET用正则表达提取数字
更新时间:2019-09-21

289人已经看过了!

判断指定路径下是否存在指定文件
更新时间:2018-12-08

147人已经看过了!

vb.net控件隐藏
更新时间:2017-11-20

204人已经看过了!

vb.net2010邮件发送带附件,带设置测试可用
更新时间:2017-08-24

168人已经看过了!

vb.net2010发送邮件
更新时间:2017-08-24

190人已经看过了!

VB.NET固定选项卡TabControl的标题宽度
更新时间:2017-06-13

201人已经看过了!