#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $Form1 = GUICreate("Form1", 615, 255, 192, 124)
Local $sSF = GUICtrlCreateInput("", 32, 24, 393, 21)
Local $sDF = GUICtrlCreateInput("", 32, 72, 393, 21)
Local $sSFB = GUICtrlCreateButton("Выбор исходной папки", 440, 24, 155, 25)
Local $sDFB = GUICtrlCreateButton("Папка назначения", 440, 64, 155, 25)
Local $Progress1 = GUICtrlCreateProgress(32, 128, 566, 17)
Local $Start = GUICtrlCreateButton("Копировать", 30, 200, 100, 25)
Global $Stop = GUICtrlCreateButton("Стоп", 225, 200, 75, 25)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $sSFB
GUICtrlSetData($sSF, FileSelectFolder('', '', 0, '', $Form1))
Case $sDFB
GUICtrlSetData($sDF, FileSelectFolder('', '', 0, '', $Form1))
Case $Start
Local $PathS = GUICtrlRead($sSF)
Local $PathD = GUICtrlRead($sDF)
If FileExists($PathS) And FileExists($PathD) Then
Global $fls = 0
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
_Copy($PathS, $PathD, $Progress1)
GUIRegisterMsg($WM_COMMAND, "")
EndIf
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $nID = BitAND($wParam, 0x0000FFFF) ; _WinAPI_LoWord
Switch $nID
Case $Stop
$fls = 1
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _Copy($sFS, $sCFD, $PR)
Local $gds = DirGetSize($sFS), $alr
Local $nCR = 1024 * 1024, $tmperc
Local $aFiles = _FileListToArrayRec($sFS, '*', 1, 1, 0, 2)
For $i = 1 To $aFiles[0]
Local $nwp = StringReplace($aFiles[$i], $sFS, $sCFD)
Local $fso = FileOpen($aFiles[$i], 16)
If $fso = -1 Then
GUICtrlSetData($PR, 0)
Return SetError(1)
EndIf
Local $fdo = FileOpen($nwp, 26)
If $fdo = -1 Then
GUICtrlSetData($PR, 0)
FileClose($fso)
Return SetError(2)
EndIf
Local $cr, $ext, $fwr, $prc, $nMsg
While 1
If $fls Then
FileClose($fso)
FileClose($fdo)
GUICtrlSetData($PR, 0)
Return
EndIf
$cr = FileRead($fso, $nCR)
$ext = @extended
If @error = -1 Then ExitLoop
$alr += $ext
$fwr = FileWrite($fdo, $cr)
If Not $fwr Then
FileClose($fso)
FileClose($fdo)
Return SetError(3)
EndIf
$prc = Floor($alr / $gds * 100)
If $tmperc < $prc Then
$tmperc = $prc
GUICtrlSetData($PR, $prc)
EndIf
WEnd
FileClose($fso)
FileClose($fdo)
Next
GUICtrlSetData($PR, 0)
EndFunc ;==>_Copy