📄 allcode.txt
字号:
Private Sub Command1_Click()
Dim fso As New FileSystemObject, drv As Drive, str As String
Set drv = fso.GetDrive(fso.GetDriveName("c:"))
str = "C盘:" & drv.VolumeName & vbCrLf
str = str & "磁盘总空间:" & FormatNumber(drv.TotalSize / 1024 / 1024, 0) & " Mb" & vbCrLf
str = str & "磁盘剩余空间" & FormatNumber(drv.FreeSpace / 1024 / 1024, 0) & "Mb"
MsgBox str
End Sub
Private Sub Command2_Click()
Dim fso As New FileSystemObject, fold As Folder
Set fold = fso.GetFolder("d:") '获得当前Drive对象
Debug.Print "当前父文件夹名是:" & fold
Debug.Print "当前驱动器名是:" & fold.Drive
fso.CreateFolder ("d:\vb") '用FileSystemObject对象在D盘上创建一个新的文件夹VB
fso.DeleteFolder ("d:\vb") '将新建文件夹删除
End Sub
Private Sub Command3_Click()
Dim fso As New FileSystemObject, fil As File, txt As TextStream, str As String
fso.CreateTextFile "c:\test.txt"
Set fil = fso.GetFile("c:\test.txt")
Set txt = fil.OpenAsTextStream(ForWriting)
txt.WriteLine ("该文件用来测试文本文件的创建!")
txt.WriteLine ("数据输入结束!") 'riteLine方法和LineInput语句功能相似
txt.Close
Set txt = fil.OpenAsTextStream(ForReading)
str = txt.ReadLine '使用Read或ReadLine时,如果要跳过数据的某些部分,可以使用Skip或SkipLine方法,ReadLine方法不读入回车换行符号
MsgBox str
txt.Close
End Sub
Private Sub Command4_Click()
Dim fso As New FileSystemObject, txt As TextStream, fil1 As File, fil2 As File
Set txt = fso.CreateTextFile("c:\test.txt", True)
MsgBox "正在写入测试文件"
txt.Write ("你好!这是一个测试例子!")
txt.Close
Set fil1 = fso.GetFile("c:\test.txt") '获得文件的句柄
fil1.Copy ("c:\temp1\test.txt") '将该文件复制到c:\temp1目录下
fil1.Move ("c:\temp2\test.txt") '将该文件移动到c:\temp2目录下
Set fil1 = fso.GetFile("c:\temp1\test.txt") '获得文件当前位置的句柄
Set fil2 = fso.GetFile("c:\temp2\test.txt")
fil1.Delete '删除文件
fil2.Delete
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -