当前位置:主页>VB教程>

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

来源: 作者: 发布时间:2008-10-22 点击次数:
OptionExplicit

  PrivateSubCommand1_Click()

  DimstrPathNameAsString 字串1

  strPathName="" 字串4

  strPathName=InputBox("请输入需要删除的文件夹名称∶","删除文件夹") 字串9

  IfstrPathName=""ThenExitSub   字串5

  OnErrorGoToErrorHandle 字串7

  SetAttrstrPathName,vbNormal'此行主要是为了检查文件夹名称的有效性 字串7

  RecurseTreestrPathName

字串9

  Label1.Caption="文件夹"&strPathName&"已经删除!"

字串2

  ExitSub

字串5

  ErrorHandle:

字串1

  MsgBox"无效的文件夹名称:"&strPathName

字串7

  EndSub   字串9

  SubRecurseTree(CurrPathAsString) 字串6

  DimsFileNameAsString 字串2

  DimnewPathAsString

字串2

  DimsPathAsString 字串3

  StaticoldPathAsString   字串6

  sPath=CurrPath&"\"  

字串5

  sFileName=Dir(sPath,31)'31的含义∶31=vbNormal vbReadOnly vbHidden vbSystem vbVolume vbDirectory

字串5

  DoWhilesFileName<>""

字串5

  IfsFileName<>"."AndsFileName<>".."Then 字串4

  IfGetAttr(sPath&sFileName)AndvbDirectoryThen'如果是目录和文件夹 字串3

  newPath=sPath&sFileName

字串4

  RecurseTreenewPath 字串8

  sFileName=Dir(sPath,31)

字串4

  Else 字串5

  SetAttrsPath&sFileName,vbNormal 字串4

  Kill(sPath&sFileName) 字串8

  Label1.Caption=sPath&sFileName'显示删除过程 字串8

  sFileName=Dir

字串2

  EndIf 字串2

  Else 字串6

  sFileName=Dir

字串5

  EndIf

字串6

  DoEvents

字串6

  Loop

字串5

  SetAttrCurrPath,vbNormal

字串4

  RmDirCurrPath

字串7

  Label1.Caption=CurrPath 字串3

  EndSub 字串7

->

字串1