'文件粉碎机程序'定义全局变量
Dim dirPath As String '要删除文件的目录路径'添加目录按钮
Function Button1_OnClick()'打开文件夹选择对话框dirPath = SelectDir("请选择要删除的文件所在目录:")If dirPath <> "" Then'显示选择的目录路径Label1.Caption = "已选择目录:" & dirPathEnd If
End Function'粉碎文件按钮
Function Button2_OnClick()If dirPath = "" ThenMsgBox "请先选择要删除的文件所在目录!", 48, "提示"Exit FunctionEnd If'遍历目录下的所有文件Dim files() As Stringfiles = ListFiles(dirPath, "*.*", 1)If UBound(files) < 0 ThenMsgBox "目录下没有找到任何文件!", 48, "提示"Exit FunctionEnd If'循环粉碎文件For i = 0 To UBound(files)'打开文件Dim fileNum As IntegerfileNum = OpenFile(files(i), 1)If fileNum <= 0 Then'无法打开文件,跳过Continue ForEnd If'获取文件大小Dim fileSize As LongfileSize = GetFileSize(files(i))'定义缓冲区Dim buffer(1024) As Byte'循环写入数据,直到覆盖整个文件Dim j As LongFor j = 1 To fileSize Step 1024WriteBytes fileNum, buffer, 1024Next'关闭文件CloseFile fileNum'删除文件DeleteFile files(i)NextMsgBox "文件粉碎完成!", 64, "提示"
End Function