用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - vb代码库

VBA 删除文件经回收站

2018-08-27 作者:layman666举报

[vb]代码库

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Long
Private Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Boolean
    hNameMappings As Long
    lpszProgressTitle As String
End Type

Public Const FO_Delete = &H3
Public Const FOF_ALLOWUNDO = &H40
Public Const HWND_DESKTOP = 0
Public Const NOCONFIRMATION = &H10 '不提示


'函数定义
Function DeleteFiles(Path As String) '定义删除文件函数
Dim Shop As SHFILEOPSTRUCT
    With Shop
        .hwnd = HWND_DESKTOP
        .pTo = ""
        .wFunc = FO_Delete
        .pFrom = Path + Chr(0)
        .fFlags = FOF_ALLOWUNDO + NOCONFIRMATION
    End With
SHFileOperation Shop
End Function
'以上是定义内容,之后可以在任意过程中调用,示例如下:
Public Sub aaaa() '调用
    DeleteFiles "C:\New Text Document.txt"
End Sub


分享到:
更多

网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。