Ordner kopieren, verschieben und löschen
ā l'Explorer
[Windows 95/98/NT/2000]

30.10.1999


Mittels API-Funktionen kann man die Windows interne
    Funktion verwenden um Ordner zu kopieren, verschieben oder zu löschen:

ERFORDERLICHE OBJEKTE
   3 Commandbuttons (Command1, Command2, Command3)
 FORM-CODE
   Const Verschieben = &H1&
   Const Kopieren = &H2&
   Const Löschen = &H3&
   Private Type SHFILEOPSTRUCT
      hwnd As Long
      wFunc As Long
      Quelle As String
      Ziel As String
      DateiFlags As Integer
      fAnyOperationsAborted As Long
      hNameMappings As Long
      lpszProgressTitle As String
   End Type
   Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" 
      (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
   Private Declare Function SHFileOperation Lib "Shell32.dll" Alias 
      "SHFileOperationA" (lpFileOp As Any) As Long
   Public Function FileOperation(Mode, Source As String, Dest As String, 
      Abfrage, Sichtbar) As Boolean
      Dim lenFileop As Long
      Dim foBuf() As Byte
      Dim fileop As SHFILEOPSTRUCT
      lenFileop = LenB(fileop)
      ReDim foBuf(1 To lenFileop)
      With fileop
        .hwnd = Me.hwnd
        .wFunc = Mode
        .Quelle = Source & vbNullChar & vbNullChar & vbNullChar
        .Ziel = Dest & vbNullChar & vbNullChar
        If Abfrage = False Then .DateiFlags = &H10&
        If Sichtbar = False Then .DateiFlags = .DateiFlags Or &H4&
        .DateiFlags = .DateiFlags Or &H40&
      End With
      Call CopyMemory(foBuf(1), fileop, lenFileop)
      Call CopyMemory(foBuf(19), foBuf(21), 12)
      FileOperation = SHFileOperation(foBuf(1)) = 0
   End Function
   Private Sub Command1_Click()
      FileOperation Kopieren, "c:\temp", "C:\neutemp", False, True
   End Sub
   Private Sub Command2_Click()
      FileOperation Verschieben, "c:\temp", "C:\neutemp", False, True
   End Sub
   Private Sub Command3_Click()
      FileOperation Löschen, "c:\temp", "", False, True
   End Sub
   Private Sub Form_Load()
      Command1.Caption = "c:\temp nach c:\neutemp kopieren"
      Command2.Caption = "c:\temp nach c:\neutemp verschieben"
      Command3.Caption = "c:\temp löschen"
   End Sub
 

 

Download - 2 KB