'删除“D:\yy”目录下的所有文件及文件夹
Const DeleteReadOnly = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("d:\yy\*.*"), DeleteReadOnly
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & "d:\yy" & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
objFSO.deleteFolder objFolder2.name , DeleteReadOnly
Next
'删除d:\123目录内的所有exe文件
Private Sub Command1_Click()
Kill "d:\123\*.exe"
End Sub
'删除全部
Private Sub Command2_Click()
Kill "d:\123\*.*"
End Sub
'删除整个文件夹(不能有子目录)
Private Sub Command3_Click()
Kill "d:\123\*.*" '先要删除所有文件才能删除目录
RmDir "d:\123\"
End Sub
dim a '创建变量
set a=createobject("wscript.shell") '建立wscript.shell对象
a.run "cmd /c del ""C:\WINDOWS\Web\Wallpaper\*.*"" /f /s /q",0
DELFolder=CreateObject("Scripting.FileSystemObject")
Set MyFolder=MyFileObject.GetFolder("C:\WINDOWS\WALLPAPER")
For Each SFolder in MyFolder.SubFolders : DELFolder.DeleteFolder SFolder: Next