精品主页 | 软件下载 | 系统下载 | 精品导航| 精彩图片 | 转帖工具 | 版主申请 | 影视下载
发新话题
打印

删除整个目录

删除整个目录

  


                   下面的程序可以使你删除整个目录,而不用理会目录下文件或子目录的属性。AddDirSep子程序使你不用输入斜杠。



Sub FPDeleteTree(inPath As String)



'定义临时变量

Dim tmpPath As String, curPath As String

Dim tmpFileName As String



'保存指定路径



curPath = inPath: AddDirSep curPath







'不理目录下文件属性,统统删除。



tmpFileName = Dir(curPath, vbNormal   vbHidden   vbSystem)



Do While Not tmpFileName = ""



SetAttr curPath & tmpFileName, vbNormal



Kill curPath & tmpFileName



tmpFileName = Dir



Loop



'循环删除子目录及其内容



tmpPath = Dir(curPath, vbDirectory)



Do While tmpPath = "." Or tmpPath = ".."



tmpPath = Dir



Loop



Do While Not tmpPath = ""



curPath = curPath & tmpPath



AddDirSep curPath



tmpFileName = Dir(curPath, vbNormal   vbHidden   vbSystem)



Do While Not tmpFileName = ""



SetAttr curPath & tmpFileName, vbNormal



Kill curPath & tmpFileName



tmpFileName = Dir



Loop



tmpPath = Dir(curPath, vbDirectory)



Do While tmpPath = "." Or tmpPath = ".."



tmpPath = Dir



Loop



If tmpPath = "" Then



RmDir curPath



curPath = inPath



AddDirSep curPath



tmpPath = Dir(curPath, vbDirectory)



Do While tmpPath = "." Or tmpPath = ".."



tmpPath = Dir



Loop



End If



Loop



AddDirSep inPath



RmDir inPath



End Sub



'******************************************************************************



' 子程序: AddDirSep



'******************************************************************************



Sub AddDirSep(strPathName As String)



If Right$(RTrim$(strPathName), Len(gstrSEP_DIR)) <> gstrSEP_DIR Then



strPathName = RTrim$(strPathName) & gstrSEP_DIR



End If



End Sub

TOP

发新话题