18-May-12
This small library allows simple and reliable way to copy or move files and directories without suspending your script. Moreover, you can get the current state (number of copied bytes, system error code, and other status information) while copying. Also supported copying or moving a multiple files and directories at once (up to 256). Working with this UDF is similar with the InetGet() function. For more information, see description for each function within the library.

Copy UDF Library v1.4 (x86 and x64)
(Previous downloads: 1162)
Copy.zip 31.19K
946 downloadsExamples
Spoiler
Copying a single file
Copying a multiple files at once
GUI, files copying
GUI, directories copying
Copying a single file
Spoiler
#Include <Misc.au3> #Include "Copy.au3" Opt('TrayAutoPause', 0) $Source = 'C:Test.tmp' $Destination = 'C:Test (2).tmp' _Copy_OpenDll() _Copy_CopyFile($Source, $Destination) Do Sleep(250) $State = _Copy_GetState() ConsoleWrite(StringFormat('%.2f%', $State[1] / $State[2] * 100) & @CR) If _IsPressed('1B') Then _Copy_Abort() EndIf Until Not $State[0] ConsoleWrite('Return code: ' & $State[5] & @CR) _Copy_CloseDll()
Copying a multiple files at once
Spoiler
AutoIt
#Include <Misc.au3> #Include "Copy.au3" Opt('TrayAutoPause', 0) $Source1 = 'C:Test1.tmp' $Destination1 = 'C:Test1 (2).tmp' $Source2 = 'C:Test2.tmp' $Destination2 = 'C:Test2 (2).tmp' _Copy_OpenDll() _Copy_CopyFile($Source1, $Destination1, 0, 0) _Copy_CopyFile($Source2, $Destination2, 0, 1) Do Sleep(250) $State1 = _Copy_GetState(0) $State2 = _Copy_GetState(1) ConsoleWrite(StringFormat('%.2f% %.2f%', $State1[1] / $State1[2] * 100, $State2[1] / $State2[2] * 100) & @CR) If _IsPressed('1B') Then _Copy_Abort(0) _Copy_Abort(1) EndIf Until (Not $State1[0]) And (Not $State2[0]) ConsoleWrite('Return code #1: ' & $State1[5] & @CR) ConsoleWrite('Return code #2: ' & $State2[5] & @CR) _Copy_CloseDll()
GUI, files copying
Spoiler
AutoIt
#Include <EditConstants.au3> #Include <GUIConstantsEx.au3> #Include "Copy.au3" Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) Global $hForm, $Input1, $Input2, $Button1, $Button2, $Button3, $Button4, $Data, $Msg, $Path, $Progress, $State, $Copy = False, $Pause = False Global $Source = '', $Destination = '' If Not _Copy_OpenDll() Then MsgBox(16, '', 'DLL not found.') Exit EndIf $hForm = GUICreate('MyGUI', 360, 163) GUICtrlCreateLabel('Source:', 14, 23, 58, 14) $Input1 = GUICtrlCreateInput('', 74, 20, 248, 19, BitOR($ES_AUTOHSCROLL, $ES_LEFT, $ES_MULTILINE)) GUICtrlSetState(-1, $GUI_DISABLE) $Button1 = GUICtrlCreateButton('...', 326, 19, 21, 21) GUICtrlCreateLabel('Destination:', 14, 55, 58, 14) $Input2 = GUICtrlCreateInput('', 74, 52, 248, 19, BitOR($ES_AUTOHSCROLL, $ES_LEFT, $ES_MULTILINE)) GUICtrlSetState(-1, $GUI_DISABLE) $Button2 = GUICtrlCreateButton('...', 326, 51, 21, 21) $Progress = GUICtrlCreateProgress(14, 94, 332, 16) $Button3 = GUICtrlCreateButton('Copy', 135, 126, 80, 21) $Button4 = GUICtrlCreateButton(';', 326, 126, 21, 21) GUICtrlSetFont(-1, 10, 400, 0, 'Webdings') GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1 If $Copy Then $State = _Copy_GetState() If $State[0] Then $Data = Round($State[1] / $State[2] * 100) If GUICtrlRead($Progress) <> $Data Then GUICtrlSetData($Progress, $Data) EndIf Else Switch $State[5] Case 0 GUICtrlSetData($Progress, 100) MsgBox(64, '', 'File was successfully copied.', 0, $hForm) Case 1235 ; ERROR_REQUEST_ABORTED MsgBox(16, '', 'File copying was aborted.', 0, $hForm) Case Else MsgBox(16, '', 'File was not copied.' & @CR & @CR & $State[5], 0, $hForm) EndSwitch GUICtrlSetData($Progress, 0) GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetState($Button2, $GUI_ENABLE) GUICtrlSetState($Button4, $GUI_DISABLE) GUICtrlSetData($Button3, 'Copy') GUICtrlSetData($Button4, ';') $Copy = 0 EndIf EndIf $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 $Path = FileOpenDialog('Select Source File', StringRegExpReplace($Source, '[^]*Z', ''), 'All Files (*.*)', 3, StringRegExpReplace($Source, '^.*', ''), $hForm) If $Path Then GUICtrlSetData($Input1, $Path) $Source = $Path EndIf Case $Button2 $Path = FileOpenDialog('Select Destination File', StringRegExpReplace($Destination, '[^]*Z', ''), 'All Files (*.*)', 2, StringRegExpReplace($Source, '^.*', ''), $hForm) If $Path Then GUICtrlSetData($Input2, $Path) $Destination = $Path EndIf Case $Button3 If $Copy Then _Copy_Abort() Else If (Not $Source) Or (Not $Destination) Then MsgBox(16, '', 'The source and destination file names must be specified.', 0, $hForm) ContinueLoop EndIf If FileExists($Destination) Then If MsgBox(51, '', $Destination & ' already exists.' & @CR & @CR & 'Do you want to replace it?', 0, $hForm) <> 6 Then ContinueLoop EndIf EndIf GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetState($Button2, $GUI_DISABLE) GUICtrlSetState($Button4, $GUI_ENABLE) GUICtrlSetData($Button3, 'Abort') _Copy_CopyFile($Source, $Destination) $Copy = 1 EndIf Case $Button4 $Pause = Not $Pause If $Pause Then GUICtrlSetData($Button4, '4') Else GUICtrlSetData($Button4, ';') EndIf _Copy_Pause($Pause) EndSwitch WEnd
GUI, directories copying
Spoiler
AutoIt
#Include <EditConstants.au3> #Include <GUIConstantsEx.au3> #Include "Copy.au3" Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) Global $hForm, $Input1, $Input2, $Button1, $Button2, $Button3, $Button4, $Label, $Data, $Msg, $Path, $Progress, $State, $Copy = False, $Pause = False Global $Source = '', $Destination = '' If Not _Copy_OpenDll() Then MsgBox(16, '', 'DLL not found.') Exit EndIf $hForm = GUICreate('MyGUI', 360, 175) GUICtrlCreateLabel('Source:', 14, 23, 58, 14) $Input1 = GUICtrlCreateInput('', 74, 20, 248, 19, BitOR($ES_AUTOHSCROLL, $ES_LEFT, $ES_MULTILINE)) GUICtrlSetState(-1, $GUI_DISABLE) $Button1 = GUICtrlCreateButton('...', 326, 19, 21, 21) GUICtrlCreateLabel('Destination:', 14, 55, 58, 14) $Input2 = GUICtrlCreateInput('', 74, 52, 248, 19, BitOR($ES_AUTOHSCROLL, $ES_LEFT, $ES_MULTILINE)) GUICtrlSetState(-1, $GUI_DISABLE) $Button2 = GUICtrlCreateButton('...', 326, 51, 21, 21) $Label = GUICtrlCreateLabel('',14, 91, 332, 14) $Progress = GUICtrlCreateProgress(14, 106, 332, 16) $Button3 = GUICtrlCreateButton('Copy', 135, 138, 80, 21) $Button4 = GUICtrlCreateButton(';', 326, 138, 21, 21) GUICtrlSetFont(-1, 10, 400, 0, 'Webdings') GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1 If $Copy Then $State = _Copy_GetState() If $State[0] Then If $State[0] = -1 Then ; Preparing Else $Data = Round($State[1] / $State[2] * 100) If GUICtrlRead($Progress) <> $Data Then GUICtrlSetData($Progress, $Data) EndIf $Data = StringRegExpReplace($State[6], '^.*', '') If GUICtrlRead($Label) <> $Data Then GUICtrlSetData($Label, $Data) EndIf EndIf Else Switch $State[5] Case 0 GUICtrlSetData($Progress, 100) MsgBox(64, '', 'Folder was successfully copied.', 0, $hForm) Case 1235 ; ERROR_REQUEST_ABORTED MsgBox(16, '', 'Folder copying was aborted.', 0, $hForm) Case Else MsgBox(16, '', 'Folder was not copied.' & @CR & @CR & $State[5], 0, $hForm) EndSwitch GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetState($Button2, $GUI_ENABLE) GUICtrlSetState($Button4, $GUI_DISABLE) GUICtrlSetData($Progress, 0) GUICtrlSetData($Label, '') GUICtrlSetData($Button3, 'Copy') GUICtrlSetData($Button4, ';') $Copy = 0 EndIf EndIf $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 $Path = FileSelectFolder('Select source folder that to be copied.', '', 2, $Source, $hForm) If $Path Then GUICtrlSetData($Input1, $Path) $Source = $Path EndIf Case $Button2 $Path = FileSelectFolder('Select destination folder in which will be copied the source directory.', '', 2, $Destination, $hForm) If $Path Then GUICtrlSetData($Input2, $Path) $Destination = $Path EndIf Case $Button3 If $Copy Then _Copy_Abort() Else If (Not $Source) Or (Not $Destination) Then MsgBox(16, '', 'The source and destination folders must be specified.', 0, $hForm) ContinueLoop EndIf $Path = $Destination & '' & StringRegExpReplace($Source, '^.*', '') If FileExists($Path) Then If MsgBox(51, 'Copy', $Path & ' already exists.' & @CR & @CR & 'Do you want to merge folders?', 0, $hForm) <> 6 Then ContinueLoop EndIf EndIf GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetState($Button2, $GUI_DISABLE) GUICtrlSetState($Button4, $GUI_ENABLE) GUICtrlSetData($Label, 'Preparing...') GUICtrlSetData($Button3, 'Abort') _Copy_CopyDir($Source, $Path, 0, 0, 0, '_Copy_CallbackDlg', $hForm) $Copy = 1 EndIf Case $Button4 $Pause = Not $Pause If $Pause Then GUICtrlSetData($Button4, '4') Else GUICtrlSetData($Button4, ';') EndIf _Copy_Pause($Pause) EndSwitch WEnd
Edited by Yashied, 17 May 2012 - 10:57 PM.








