1.基本的文件操作,如重命名,移动,删除,新建,文件大小,具体代码如下所示
Option Explicit
Sub 演示()
Dim strpath As String, filename As String
strpath = ThisWorkbook.path & "\"
'filename = "text.txt"
'MsgBox FileLen(strpath & filename) '文件大小
filename = "text.txt"
' Name strpath & filename As strpath & "text_命名.txt" '重命名或者移动路径
' Name strpath & "\1" As strpath & "\2" '重命名文件夹
'filname = "text.txt"
'FileCopy strpath & filename, strpath & "tast_beifeng.text" '复制文件
'Kill strpath & "\test.txt" '删除文件
' MkDir strpath & 1 '创建文件夹
' RmDir strpath & 1 '删除文件夹,(仅限空文件夹)
End Sub
2.文件加密(就是将文件的每一个字符用dog的每一个字符取它的ASCII值,再显示出来。)
Option Explicit
Sub 文件加密()
Dim filename As String
filename = ThisWorkbook.path & "\text.txt"
Open filename For Binary As #1
Dim i As Integer, ch As Byte, dog As String, j As Integer
dog = "asddfx"
For i = 1 To LOF(1)
Get #1, , ch
'把ch 与dog的每一位进行一次异或
For j = 1 To Len(dog)
ch = ch Xor Asc(Mid(dog, j, 1))
Next j
Put #1, , ch
Next i
Close #1
End Sub