dim TempStr as string
TempStr=dir(目录)
do while not tempstr=""
     kill tempstr
     tempstr=dir
loop
这样应该可以。我可没试试过啊。你自已试试dir 不加参数可以历遍第一次给的目录的所有文件

解决方案 »

  1.   


        采用递归算法删除带有多级子目录的目录
     
     Option ExplicitPrivate Sub Command1_Click()
    Dim strPathName As String
    strPathName = ""
    strPathName = InputBox("请输入需要删除的文件夹名称∶", "删除文件夹")
    If strPathName = "" Then Exit SubOn Error GoTo ErrorHandle
    SetAttr strPathName, vbNormal '此行主要是为了检查文件夹名称的有效性
    RecurseTree strPathName
    Label1.Caption = "文件夹" & strPathName & "已经删除!"
    Exit Sub
    ErrorHandle:
    MsgBox "无效的文件夹名称:" & strPathName
    End SubSub RecurseTree(CurrPath As String)
    Dim sFileName As String
    Dim newPath As String
    Dim sPath As String
    Static oldPath As StringsPath = CurrPath & "\"sFileName = Dir(sPath, 31) '31的含义∶31=vbNormal+vbReadOnly+vbHidden+vbSystem+vbVolume+vbDirectory
    Do While sFileName <> ""
    If sFileName <> "." And sFileName <> ".." Then
    If GetAttr(sPath & sFileName) And vbDirectory Then '如果是目录和文件夹
    newPath = sPath & sFileName
    RecurseTree newPath
    sFileName = Dir(sPath, 31)
    Else
    SetAttr sPath & sFileName, vbNormal
    Kill (sPath & sFileName)
    Label1.Caption = sPath & sFileName '显示删除过程
    sFileName = Dir
    End If
    Else
    sFileName = Dir
    End If
    DoEvents
    Loop
    SetAttr CurrPath, vbNormal
    RmDir CurrPath
    Label1.Caption = CurrPath
    End Sub
     
       
     
      
     
      

  2.   

    : powpow(飞机)的方法可以吗?
      

  3.   

    简单的就是用fos
    想自己写还可以这样:
    我这里有一个找出某个目录下所有文件的大小的程序段,原理是找出所有的文件并计算它的文件大小,你改一两行就可以行到所有的文件名与子目录,然后就
    删除它们就可以了..
    Dim  TotalDir(0  To  100)  
    Dim  TotalFileSize  As  Double  
      
    Sub  CountTotalFileSize(ByVal  DirPath)  '计算目录所有的文件的大小  
            Dim  MyPath,  MyName,  i  As  Byte,  j  As  Byte  
            If  Right(DirPath,  1)  <  >    "\"  Then  DirPath  =  DirPath  &    "\"        '如果尾部没斜杠就在尾部加一个斜杠  
            MyName  =  Dir(DirPath,  vbDirectory)  
              
            '查找DirPath文件夹下的文件或文件夹  
            '如是文件夹就把文件夹名加入数组TotalDir里面  
            '否则就把其文件大小加入TotalFileSize  
            Do  While  MyName  <  >    ""  
                    If  MyName  <  >    "."  And  MyName  <  >    ".."  Then  
                            If  GetAttr(DirPath  &    MyName)  =  vbDirectory  Then  
                                    For  i  =  0  To  UBound(TotalDir,  1)
                                            If  TotalDir(i)  =  ""  Then
                                                    TotalDir(i)  =  DirPath  &    MyName
                                                    Exit  For
                                            End  If
                                    Next
                            Else
                                    TotalFileSize  =  TotalFileSize  +  FileLen(DirPath  &    MyName)
                            End  If
                    End  If
                    MyName  =  Dir
            Loop
            '把整个数组的数据向前移一位,即把刚刚查找完毕的文件夹名删除,节约资源
            For  i  =  0  To  UBound(TotalDir,  1)
                    If  TotalDir(i)  =  ""  Then
                            For  j  =  0  To  i  -  1
                                    TotalDir(j)  =  TotalDir(j  +  1)
                            Next
                            Exit  For
                    End  If
            Next
    End  Sub  
    Function  ShowDirSize(ByVal  DirPath)       For  j  =  0  To  UBound(TotalDir,  1)
                    TotalDir(j)  =  ""       Next
            TotalDir(0)  =  DirPath        TotalFileSize  =  0
            Do  While  TotalDir(0)  <  >    ""
                    Call  CountTotalFileSize(TotalDir(0))
            Loop
            ShowDirSize  =  TotalFileSize  
    End  FunctionPrivate  Sub  Command1_Click()
            Print  ShowDirSize("d:\web\"  &    "  bytes")
    End  Sub
      

  4.   

    '可以使用FileSystemObject
    '如:Private Function DeleteFile(ByVal strPathName As String, Optional mFlags As Boolean = False) As Boolean
        On Error Resume Next
        Dim FSO As New FileSystemObject
        Dim mFile As File, mFolder As Folder
        If FSO.FolderExists(strPathName) Then
            Set mFolder = FSO.GetFolder(strPathName)
            For Each mFile In mFolder.Files
                FSO.DeleteFile mFile.Path, mFlags
            Next mFile
        End If
        If Err.Number <> 0 Then
            MsgBox Err.Description, vbInformation + vbOKOnly, "Errcode:" & Err.Number
            Err.Clear
            DeleteFile = False
        Else
            DeleteFile = True
        End If
    End Function
      

  5.   

    请问你们的方法可以删除系统目录吗?
    请看看我的问题:
    http://www.csdn.net/expert/topic/614/614098.xml?temp=.5745203
    http://www.csdn.net/expert/topic/611/611114.xml?temp=.484646