4 回答
TA贡献1893条经验 获得超10个赞
假如我要删除D盘里所有的txt文件该怎样编写呢?
Kill "D:\*.txt"
这样只能删除根目录下的,得自已写一个循环
假如我要删除D盘的所有东西(包括文件夹)又该怎样编写呢?
直接格式化就行了 删除多慢啊
TA贡献1784条经验 获得超9个赞
一、建立一个模块,复制下面代码:
Private Const FO_MOVE = &H1
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_RENAME = &H4
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_SILENT = &H4
Private Const FOF_NOERRORUI = &H400
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
'删除目录扩展(不管目录内有无文件,一次性删除目录)
Function KillFolder(CurrPath As String) As Boolean
On Error Resume Next
Dim udtPath As SHFILEOPSTRUCT
udtPath.hwnd = 0
udtPath.wFunc = FO_DELETE
udtPath.pFrom = CurrPath
udtPath.pTo = ""
udtPath.fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOERRORUI
KillFolder = Not CBool(SHFileOperation(udtPath))
End Function
二、调用举例:
KillFolder "d:\" '此命令将删除d盘所有数据,请慎重!
三、说明:如果目录内的文件正在被调用,那么将无法删除该目录。
- 4 回答
- 0 关注
- 1014 浏览
添加回答
举报