⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filenamehandle.vb

📁 文件复制器 2007.07.28.0最新VB源代码 地狱门神(F.R.C.) 适用范围 Windows环境下
💻 VB
字号:
'==========================================================================
'
'  File:        FileNameHandle.vb
'  Location:    FileSystem <Visual Basic .Net>
'  Description: 文件名操作函数模块
'  Version:     2007.07.22.
'  Copyright(C) F.R.C.
'
'==========================================================================

Option Strict On
Option Compare Text

Public Module FileNameHandle
    Public Function GetFileName(ByVal FilePath As String) As String
        If FilePath = "" Then Return ""
        Dim NameS As Integer
        Dim NameS2 As Integer = FilePath.IndexOf("\"c, NameS)
        While NameS2 <> -1
            NameS = NameS2 + 1
            NameS2 = FilePath.IndexOf("\"c, NameS)
        End While
        Return FilePath.Substring(NameS)
    End Function
    Public Function GetMainFileName(ByVal FilePath As String) As String
        If FilePath = "" Then Return ""
        Dim NameS As Integer
        Dim NameS2 As Integer = FilePath.IndexOf("\"c, NameS)
        While NameS2 <> -1
            NameS = NameS2 + 1
            NameS2 = FilePath.IndexOf("\"c, NameS)
        End While
        Dim NameE As Integer = FilePath.Length - 1
        Dim NameE2 As Integer = FilePath.LastIndexOf("."c, NameE)
        If NameE2 <> -1 Then
            NameE = NameE2 - 1
        End If
        Return FilePath.Substring(NameS, NameE - NameS + 1)
    End Function
    Public Function GetExtendedFileName(ByVal FilePath As String) As String
        If FilePath = "" Then Return ""
        If Not FilePath.Contains(".") Then Return ""
        Return FilePath.Substring(FilePath.LastIndexOf(".") + 1)
    End Function
    Public Function GetFileDirectory(ByVal FilePath As String) As String
        If FilePath = "" Then Return ""
        Dim NameE As Integer
        Dim NameE2 As Integer
        While NameE2 <> -1
            NameE = NameE2 + 1
            NameE2 = FilePath.IndexOf("\"c, NameE)
        End While
        Return FilePath.Substring(0, NameE - 1)
    End Function
    Public Function GetRelativePath(ByVal FilePath As String, ByVal BaseDirectory As String) As String
        If FilePath = "" OrElse BaseDirectory = "" Then Return FilePath
        Dim RelativePath As String = ""
        Dim a As String = FilePath.TrimEnd("\"c)
        Dim b As String = BaseDirectory.TrimEnd("\"c)
        Dim c As String
        Dim d As String

        c = PopFirstDir(a)
        d = PopFirstDir(b)
        If c <> d Then Return FilePath
        While c = d
            If c = "" Then Return "."
            c = PopFirstDir(a)
            d = PopFirstDir(b)
        End While

        a = (c & "\" & a).TrimEnd("\"c)
        b = (d & "\" & b).TrimEnd("\"c)

        While PopFirstDir(b) <> ""
            a = "..\" & a
        End While
        Return a
    End Function
    Private Function PopFirstDir(ByRef Path As String) As String
        Dim ret As String
        If Path = "" Then Return ""
        Dim NameS As Integer
        NameS = Path.IndexOf("\"c, NameS)
        If NameS < 0 Then
            ret = Path
            Path = ""
            Return ret
        Else
            ret = Path.Substring(0, NameS)
            Path = Path.Substring(NameS + 1)
            Return ret
        End If
    End Function
    Public Function GetPath(ByVal Directory As String, ByVal FileName As String) As String
        If Directory = "" Then Return FileName
        Directory = Directory.TrimEnd("\"c)
        Return Directory & "\" & FileName
    End Function

    Public Function IsMatchFileMask(ByVal FileName As String, ByVal Mask As String) As Boolean
        Return FileName Like Mask
    End Function
End Module

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -