vb删除文件夹:在vb中删除带子文件夹的文件夹



OptionExplicit
  PrivateSubCommand1_Click
  DimstrPathNameAsString
  strPathName=\"\"
  strPathName=InputBox(\"请输入需要删除文件夹名称∶\",\"删除文件夹\")
  IfstrPathName=\"\"ThenExitSub  
  OnErrorGoToErrorHandle
  SetAttrstrPathName,vbNormal\'此行主要是为了检查文件夹名称有效性
  RecurseTreestrPathName
  Label1.Caption=\"文件夹\"&strPathName&\"已经删除!\"
  ExitSub
  ErrorHandle:
  MsgBox\"无效文件夹名称:\"&strPathName
  EndSub  
  SubRecurseTree(CurrPathAsString)
  DimsFileNameAsString
  DimPathAsString
  DimsPathAsString
  StaticoldPathAsString  
  sPath=CurrPath&\"\\\"  
  sFileName=Dir(sPath,31)\'31含义∶31=vbNormal vbReadOnly vbHidden vb vbVolume vbDirectory
  DoWhilesFileName<>\"\"
  IfsFileName<>\".\"AndsFileName<>\"..\"Then
  IfGetAttr(sPath&sFileName)AndvbDirectoryThen\'如果是目录和文件夹
  Path=sPath&sFileName
  RecurseTreePath
  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
Tags:  vb创建文件夹 vb打开文件夹 vb.net删除文件夹 vb删除文件夹

延伸阅读

最新评论

发表评论