检测文件是否存在 返回主页 
Function FileExists(FileName As String) As Boolean
    On Error Resume Next
    FileExists = Dir$(FileName) <> ""
    If Err.Number <> 0 Then
        FileExists = False
    End If
    On Error GoTo 0
End Function 
 采用递归算法删除带有多级子目录的目录 
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
 
将两个程序结合起来,或者搜索硬盘上的user.db搜索到,删除所在文件夹
你是不是针对oicq来的

解决方案 »

  1.   

    Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As LongPrivate Sub Form_Load()
        Dim Buffer As String, Ret As Long
        'create a buffer
        Buffer = Space(255)
        'copy the current directory to the buffer and append 'myfile.ext'
        Ret = GetFullPathName("user.db", 255, Buffer, "")
        'remove the unnecessary chr$(0)'s
        Buffer = Left(Buffer, Ret)
        'show the result
        'MsgBox Buffer
        
        'Delete Folder
        RmDir Left(Buffer,Len(Buffer)-Len(user.db)-1)
    End Sub