Option Explicit '对文件进行操作的代码
Public Sub 同步(文件1 As String, 文件2 As String)
End Sub
'判断文件或者文件夹是否存在 Public Function 存在(Path As String) As Boolean If Right(Path, 1) = "\" Then Path = Left(Path, Len(Path) - 1) If Len(Trim(Path)) < 1 Then Exit Function '判断是否存在 If Dir(Path, vbDirectory Or vbHidden Or vbSystem Or vbNormal Or vbReadOnly) <> "" Then '判断是否文件夹 If (GetAttr(Path) And vbDirectory) <> vbDirectory Then 存在 = True '是文件 Else 存在 = False End If End If End Function
Public Sub StringSave(S As String, sPath As String) Dim BB() As Byte, I As Long, C As Long S = StrConv(S, vbFromUnicode) BB = S For I = UBound(BB) To 0 Step -1 If BB(I) <> 0 Then C = I Exit For End If Next I ReDim Preserve BB(C) Call BinSave(BB, sPath) End Sub
'保存二进制到文件 Public Sub BinSave(B() As Byte, sPath As String) Dim FreeNum As Integer FreeNum = FreeFile() If Dir(sPath) <> "" Then Kill (sPath) Open sPath For Binary As #FreeNum Put #FreeNum, , B Close #FreeNum End Sub
Public Function ToBin(Path As String) As Byte() Dim FreeNum As Integer FreeNum = FreeFile() ReDim ToBin(FileLen(Path)) Open Path For Binary As #FreeNum Get #FreeNum, , ToBin Close #FreeNum End Function
'返回文件的文本内容,已经自动转换为Unicode编码 Public Function ToString(Path As String) As String ToString = ToBin(Path) ToString = StrConv(ToString, vbUnicode) End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '功能:文件名处理,如文件名为"c:\VbStudy\va3.exe" //
Public Function 路径(Path As String) As String 路径 = Left(Path, InStrRev(Path, "\")) End Function
'c:\VbStudy\va3 Public Function 无扩展名全路径(Path As String) As String 无扩展名全路径 = Left(Path, Len(Path) - Len(扩展名(Path))) End Function
Public Function 文件名(Path As String) As String 文件名 = Right(Path, Len(Path) - Len(路径(Path))) End Function
Public Function 扩展名(Path As String) As String Dim temp() As String If InStr(Path, ".") = 0 Then Exit Function temp = Split(Path, ".") 扩展名 = "." & temp(UBound(temp)) End Function
Public Function 盘符(Path As String) As String 盘符 = Left(Path, 1) End Function
|