怎样用VBA删除根目录下的所有文件及文件夹

比如把在D盘下的文件全部删除。

请小心使用以下代码!!后果自负
Sub DelAll()
strpathname = "D:\"
CreateObject("scripting.filesystemobject").getfolder(strpathname).Delete True
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-07-21
Sub Test()
EnumFiles ("D:")
End Sub

Sub EnumFiles(ByVal sPath As String)
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
GetFile fso.getfolder(sPath)
Set fso = Nothing
End Sub

Sub GetFile(ByVal fldParent As Folder)
Dim fldSub As Folder, fSub As File
For Each fldSub In fldParent.SubFolders
fldSub.Delete True
Next
For Each fSub In fldParent.Files
fSub.Delete True
Next
Set fldSub = Nothing
Set fSub = Nothing
End Sub

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网