Feedback

VB - Datei mittels Windows Dialog löschen

Veröffentlicht von am 6/3/2006
(3 Bewertungen)
Datei mittels Windows Dialog löschen
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

Private Structure SHFILEOPSTRUCT
    Dim hwnd As Integer
    Dim wFunc As Integer
    Dim pFrom As String
    Dim pTo As String
    Dim fFlags As Short
    Dim fAnyOperationsAborted As Boolean
    Dim hNameMappings As Integer
    Dim lpszProgressTitle As String
End Structure

Const FO_DELETE As Short = &H3S
Const FOF_NOCONFIRMATION As Short = &H10S
Const FOF_ALLOWUNDO As Short = &H40S

Public Function ShellErase(ByVal strSource As String, ByVal Move2Bin As Boolean, ByVal WithDialog As Boolean, ByVal Handle As Long) As Boolean
    Dim SFO As New SHFILEOPSTRUCT

    If Right(strSource, 1) = "\" Then strSource = Mid(strSource, 1, Len(strSource) - 1)
    ShellErase = True
    With SFO
        .hwnd = Handle
        .wFunc = FO_DELETE
        .pFrom = strSource & Chr(0) & Chr(0)
        .pTo = "" & Chr(0) & Chr(0)
        If Move2Bin = True Then
            .fFlags = FOF_ALLOWUNDO
            If WithDialog = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION
        Else
            If WithDialog = False Then .fFlags = FOF_NOCONFIRMATION
        End If
    End With

    Call SHFileOperation(SFO)
    If SFO.fAnyOperationsAborted Then ShellErase = False
End Function
Abgelegt unter Shell, Datei, Löschen.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!