- Код: Выделить всё
Option Explicit
Private Declare Function SHFileOperation Lib "shell32" Alias "SHFileOperationW" (ByVal lpFileOp As Long) As Long
Private Const FO_COPY = &H2
Private Const FOF_SILENT = &H4
Private Const FOF_NOCONFIRMATION = &H10
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Public Function UnpackingZIP(ByVal Source As String, ByVal DestinationFolder As String, Optional ShowProgress As Boolean) As Boolean
Dim SHF As SHFILEOPSTRUCT
Dim pFrom As String
pFrom = Source & "\*.*" & vbNullChar
SHF.hwnd = hwnd
SHF.wFunc = FO_COPY
If Not ShowProgress Then
SHF.fFlags = FOF_SILENT Or FOF_NOCONFIRMATION
Else
SHF.fFlags = FOF_NOCONFIRMATION
End If
SHF.pFrom = pFrom & vbNullChar
SHF.pTo = DestinationFolder
If SHFileOperation(VarPtr(SHF)) = 0 Then UnpackingZIP = True
End Function
Private Sub Command1_Click()
Screen.MousePointer = 13
If UnpackingZIP(Text1.Text, Text2.Text) = True Then
Screen.MousePointer = 0
MsgBox "All files have been successfully copied!", vbInformation
Else
Screen.MousePointer = 0
MsgBox "File copying error, 0 files were copied.", vbCritical
End If
End Sub
Private Sub Form_Load()
Text1.Text = AppPath & "\TestSource.zip"
Text2.Text = AppPath & "\TestDestination"
End Sub