用FileSystemObject不是挺好?直接就可以删。

解决方案 »

  1.   

    我不想用fso这样做没意义,我想学api,请各位高手指教.
      

  2.   

    这个绝对不能呼叫 VB 所提供的 Kill 叙述, Kill 叙述只会将档案从磁碟中删除, 若要将档案丢到资源回收筒, 必须呼叫 SHFileOperation API 函数, 假设我们想将 c:\test.txt 丢到资源回收筒, 则呼叫的叙述如下:
    Dim SHFileOp As SHFILEOPSTRUCT
    SHFileOp.wFunc = FO_DELETESHFileOp.pFrom = "c:\test.txt" + Chr(0)SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATIONCall SHFileOperation(SHFileOp)
    在以上叙述中有几件值得注意的事情:
    FOF_ALLOWUNDO 表示被删除的档案将来可以还原, 此一设定值是绝对必要的。 
    FOF_NOCONFIRMATION 表示不显示交谈窗询问使用者「是否将档案丢到资源回收筒」, 若要询问使用者, 则应取消此一设定值。 
    请注意 "c:\test.txt" 之後必须加上 Chr(0)。 
    利用以上方法也可以一次删除多个档案, 此时只要将多个档案名称串在一起, 并且以 Chr(0) 分隔即可, 假设我们想删除 c:\test1.txt、c:\test2.txt、及 c:\test3.txt 等叁个档案, 则程式如下:
    Dim SHFileOp As SHFILEOPSTRUCT
    Dim Files As String
    Files = "c:\test1.txt" + Chr(0) + "c:\test2.txt" + Chr(0) + "c:\test3.txt" + Chr(0)SHFileOp.wFunc = FO_DELETESHFileOp.pFrom = FilesSHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATIONCall SHFileOperation(SHFileOp)How to empty the Recycle Bin within a VB-Application using the API
    Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As LongPrivate Const SHERB_NORMAL = &H0 'Normal executionPrivate Const SHERB_NOCONFIRMATION = &H1 'execute without confirmationPrivate Const SHERB_NOPROGRESSUI = &H2 'execute without progress windowPrivate Const SHERB_NOSOUND = &H4 'execute without soundPrivate Const SHERB_NOALL = (SHERB_NOCONFIRMATION And SHERB_NOPROGRESSUI And SHERB_NOSOUND)
    Dim RetVal As LongPrivate Sub EmpRecBin()
        RetVal = SHEmptyRecycleBin(0&, vbNullString, SHERB_NORMAL)
    End Sub 如果要详细信息我有一个例子
    [email protected]