如何删除指定目录下的纯数字文件夹(文件夹里有子目录),文件夹里有很多目录和文件,我只要判断目录里哪些文件夹是以纯数字命名的,然后把他删除,,,,,,,

解决方案 »

  1.   


    Public Function search(ByVal strPath As String) As Boolean
    Dim strFileDir() As String
    Dim strFile As String
    Dim i As LongDim lDirCount As Long
    On Error GoTo MyErr
    If Right(strPath, 1) <> "" Then strPath = strPath + ""
    strFile = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
    While strFile <> "" '搜索当前目录
    DoEvents
    If (GetAttr(strPath + strFile) And vbDirectory) = vbDirectory Then '如果找到的是目录
        If strFile <> "." And strFile <> ".." Then '排除掉父目录(..)和当前目录(.)
            lDirCount = lDirCount + 1 '将目录数增1
            ReDim Preserve strFileDir(lDirCount) As String
            strFileDir(lDirCount - 1) = strFile '用动态数组保存当前目录名
            If IsNumeric(strFile) = True Then '如果是纯数字文件夹删除
                '这里是删除的代码
                lDirCount = lDirCount + 1
                ReDim Preserve strFileDir(lDirCount) As String
            End If
        End If
    End If
    strFile = Dir
    Wend
    For i = 0 To lDirCount - 1
        Call search(strPath + strFileDir(i)) '递归搜索子目录
    Next
    ReDim strFileDir(0) '将动态数组清空
    search = True '搜索成功
    Exit Function
    MyErr:
    search = False '搜索失败
    End Function
      

  2.   

    xrename初步设计是有这功能的,不过貌似还没来得及完成includesubdir功能呢,你参考下:4.删除文件,语法:
    delfile -dir directory -string string1 [-type (file|dir|all)[:string3]] [-includesubdir (yes|no)] [-ignorecase (yes|no)] [-log (yes|no)]功能说明:删除某个目录下符合指定规则的文件或文件夹。参数说明:参考replace功能的参数说明部分。应用范例:
    (1)删除"c:\movie\"下所有文件名含有"美2010情景喜剧片"的文件
    XRename delfile -dir "c:\movie\" -string "美2010情景喜剧片"(2)删除"c:\test\"下所有目录名为数字的目录,包含子目录。includesubdir 表示是否包含子目录
    XRename delfile -dir "c:\test\" -string "^\d+$" -type dir -includesubdir yesxrename介绍:http://blog.csdn.net/sysdzw/archive/2011/02/21/6198257.aspx
    xrename源码:http://blog.csdn.net/sysdzw/archive/2011/02/28/6213821.aspx
      

  3.   

    4楼的代码都注释的很多,但是我要搜索的不是当前目录,我要搜索的是绝对路径,比如"C:\Documents and Settings\Administrator\aa",不知道要把绝对路径添加到上面代码的什么地方,还有就是当单击按钮1执行,个人比较菜,不知道如何去改,,,,
      

  4.   


    上面是一个过程,用到递归的,其调用参数就是要搜索的路径~~~
    t=search("C:\Documents and Settings\Administrator\aa")
      

  5.   

    如果数字文件夹里还有非数字文件夹,如11\aa 或 11\aa\12\c,这类情况如何删除呢?还是把11删除。
      

  6.   

    删除指定目录下(比如C:\Documents and Settings\Administrator\123)文件及其所有子目录
    shell "rd /s /q ""C:\Documents and Settings\Administrator\123""",vbHide
      

  7.   

    楼上我想问下,为什么哥们你对autohotkey情有独钟,看到你就条件反射的想到autohotkey就像电视里出现那3d的动画立刻想到脑白金
      

  8.   

    dos留下的人都有这习惯吧!我也常用...
      

  9.   

    4楼的你好,完整的代码是下面的吗?我测试无效,,路径下后面的目录是隐藏的,,把On Error GoTo MyErr
    注释掉,会提示文件未找到,并黄色高亮显示If (GetAttr(strPath + strFile) And vbDirectory) = vbDirectory Then '如果找到的是目录
    Public Function search(ByVal strPath As String) As Boolean
    Dim strFileDir() As String
    Dim strFile As String
    Dim i As LongDim lDirCount As Long
    On Error GoTo MyErr
    If Right(strPath, 1) <> "" Then strPath = strPath + ""
    strFile = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
    While strFile <> "" '搜索当前目录
    DoEvents
    If (GetAttr(strPath + strFile) And vbDirectory) = vbDirectory Then '如果找到的是目录
        If strFile <> "." And strFile <> ".." Then '排除掉父目录(..)和当前目录(.)
            lDirCount = lDirCount + 1 '将目录数增1
            ReDim Preserve strFileDir(lDirCount) As String
            strFileDir(lDirCount - 1) = strFile '用动态数组保存当前目录名
            If IsNumeric(strFile) = True Then '如果是纯数字文件夹删除
                '这里是删除的代码
                lDirCount = lDirCount + 1
                ReDim Preserve strFileDir(lDirCount) As String
            End If
        End If
    End If
    strFile = Dir
    Wend
    For i = 0 To lDirCount - 1
        Call search(strPath + strFileDir(i)) '递归搜索子目录
    Next
    ReDim strFileDir(0) '将动态数组清空
    search = True '搜索成功
    Exit Function
    MyErr:
    search = False '搜索失败
    End Function
    Private Sub Command1_Click()
          search("C:\Documents and Settings\Administrator\Local Settings\Application Data\aa")
    End Sub
      

  10.   

    将他函数里的If Right(strPath, 1) <> "" Then strPath = strPath + ""改成:
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
      

  11.   

    我是问他关于autohotkey的,这个软件在dos时代下用的?
    rd命令我也常用,我意思是还得遍历判断,不光光是删除一个文件夹,用批处理都处理出来还是有点小复杂的。
      

  12.   


     '这里是删除的代码
    替换为
    shell "rd /s /q """+strFile+"""",vbHide  '删除strFile目录及其子目录
    试试?计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……
      

  13.   

    获取指定目录比如C:\Documents and Settings\Administrator\Local Settings\Application Data\下所有目录及其子目录的名字:
    dim mydir as string
    mydir="C:\Documents and Settings\Administrator\Local Settings\Application Data\"
    shell "dir /b /s /ad """+mydir+"*.*"" >d:\alldirs.txt",vbHide
    '然后按行读文件d:\alldirs.txt的内容BTW:AutoHotKey是在Windows下用的。
      

  14.   

    可是为什么哥们你对autohotkey情有独钟,是你们公司的产品么?
    看到你的id我就条件反射的想到autohotkey就像电视里出现那3d两个小人的动画广告就立刻想到脑白金不过这两者我都没用过
      

  15.   

    http://download.csdn.net/source/3384863
      

  16.   

    还是没用,把On Error GoTo MyErr注释掉后,会出现:
    实时错误 '28'堆栈空间溢出然后会黄色高亮 Call search(strPath + strFileDir(i)) '递归搜索子目录怎么办,,大家知道的帮帮我吧,,,,,