在Visual Basic中删除带子文件夹的文件夹

来源:网络时间:2021-12-23 00:12:41

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

本文内容为用户投稿,该文观点仅代表作者本人,不代表本站立场,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请将相关资料发送至rjfawu@163.com进行反馈与投诉,一经查实,立即处理!