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



option explicit   private sub command1_click

  dim strpathname as

  strpathname = \"\"

  strpathname = inputbox(\"请输入需要删除文件夹名称∶\", \"删除文件夹\")

   strpathname = \"\" then exit sub  

  on error goto errorhandle

  attr strpathname, vbnormal \'此行主要是为了检查文件夹名称有效性

  recurree strpathname

  label1.caption = \"文件夹\" & strpathname & \"已经删除!\"

  exit sub

  errorhandle:

  msgbox \"无效文件夹名称:\" & strpathname

  end sub  

  sub recurree(currpath as )

  dim sfilename as

  dim path as

  dim spath as

   oldpath as   

  spath = currpath & \"\\\"  

  sfilename = dir(spath, 31) \'31含义∶31=vbnormal+vbreadonly+vbhidden+vbsystem+vbvolume+vbdirectory

  do while sfilename <> \"\"

   sfilename <> \".\" and sfilename <> \"..\" then

   getattr(spath & sfilename) and vbdirectory then \'如果是目录和文件夹

  path = spath & sfilename

  recurree path

  sfilename = dir(spath, 31)

  

  attr spath & sfilename, vbnormal

  kill (spath & sfilename)

  label1.caption = spath & sfilename \'显示删除过程

  sfilename = dir

  end

  

  sfilename = dir

  end

  doevents

  loop

  attr currpath, vbnormal

  rmdir currpath

  label1.caption = currpath

  end sub

Tags:  vb创建文件夹 vb打开文件夹 vb.net删除文件夹 vb删除文件夹

延伸阅读

最新评论

发表评论