OptionExplicit
PrivateSubCommand1_Click()
DimstrPathNameAsString
strPathName=""
strPathName=InputBox("请输入需要删除的文件夹名称∶","删除文件夹")
IfstrPathName=""ThenExitSub
OnErrorGoToErrorHandle
SetAttrstrPathName,vbNormal'此行主要是为了检查文件夹名称的有效性
RecurseTreestrPathName
Label1.Caption="文件夹"&strPathName&"已经删除!"
ExitSub
ErrorHandle:
MsgBox"无效的文件夹名称:"&strPathName
EndSub
SubRecurseTree(CurrPathAsString)
DimsFileNameAsString
DimnewPathAsString
DimsPathAsString
StaticoldPathAsString
sPath=CurrPath&""
sFileName=Dir(sPath,31)'31的含义∶31=vbNormal vbReadOnly vbHidden vbSystem vbVolume vbDirectory
DoWhilesFileName<>""
IfsFileName<>"."AndsFileName<>".."Then
IfGetAttr(sPath&sFileName)AndvbDirectoryThen'如果是目录和文件夹
newPath=sPath&sFileName
RecurseTreenewPath
sFileName=Dir(sPath,31)
Else
SetAttrsPath&sFileName,vbNormal
Kill(sPath&sFileName)
Label1.Caption=sPath&sFileName'显示删除过程
sFileName=Dir
EndIf
Else
sFileName=Dir
EndIf
DoEvents
Loop
SetAttrCurrPath,vbNormal
RmDirCurrPath
Label1.Caption=CurrPath
EndSub
希望这篇
在Visual Basic中的删除带子文件夹的文件夹的文章能够对您有所帮助,如果您觉得这篇网站维护教程有用的话,别忘了推荐给您的朋友哦!如果您有好的经验方法,不妨拿出来和大家一起分享:假如每个人都拿出一个经验,那么我们都将额外的获取一堆他人的经验。
请记住本站永久域名:(黑客防线网安服务器维护方案维护基地)Www.Rongsen.Com.Cn