Jump to content



Photo

Copy UDF


  • Please log in to reply
68 replies to this topic

#1 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 05 November 2010 - 08:26 PM

LAST VERSION - 1.4
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.


Posted Image



Copy UDF Library v1.4 (x86 and x64)
(Previous downloads: 1162)

Attached File  Copy.zip   31.19K   956 downloads


Examples

Spoiler

Edited by Yashied, 17 May 2012 - 10:57 PM.

  • KaFu and ESATU like this







#2 Emiel Wieldraaijer

Emiel Wieldraaijer

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 651 posts

Posted 05 November 2010 - 08:40 PM

Yashied

You rock.. Thanks for this UDF

Best regards,

Emiel
Best regards,Emiel WieldraaijerPosted Image

#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 06 November 2010 - 10:35 PM

Another example of a recursive copying directories (like Explorer). Here the "Source" and "Destination" folders should exist on disk.

AutoIt         
#Include <Copy.au3> #Include <GUIConstantsEx.au3> Opt('GUIOnEventMode', 1) Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) Global Const $Source = 'C:\Source' Global Const $Destination = 'C:\Destination' Global $hForm, $Button, $Label1, $Label2, $Progress1, $Progress2 Global $DirSize, $CurSize, $Abort = False If Not _Copy_OpenDll() Then     MsgBox(16, '', 'Copy.dll not found.')     Exit EndIf $hForm = GUICreate('Copying', 400, 146) GUISetOnEvent($GUI_EVENT_CLOSE, '_Event') $Label1 = GUICtrlCreateLabel($Destination, 16, 17, 368, 14) GUICtrlSetData(-1, $Destination) $Progress1 = GUICtrlCreateProgress(16, 33, 368, 16) $Label2 = GUICtrlCreateLabel('Prepare...', 16, 63, 368, 14) $Progress2 = GUICtrlCreateProgress(16, 79, 368, 16) $Button = GUICtrlCreateButton('Cancel', 305, 110, 80, 25) GUICtrlSetState(-1, $GUI_DEFBUTTON) GUICtrlSetOnEvent(-1, '_Event') GUISetState() _Copy($Source, $Destination) Switch @error     Case 0         MsgBox(64, '', 'The files copying is complete successfully.', 0, $hForm)     Case 1235 ; ERROR_REQUEST_ABORTED         MsgBox(16, '', 'The files copying was aborted by user.', 0, $hForm)     Case Else         MsgBox(16, '', 'The files not copied. ' & @CR & @CR & @error, 0, $hForm) EndSwitch _Copy_CloseDll() Func _Event()     Switch @GUI_CtrlID         Case $GUI_EVENT_CLOSE             Exit         Case $Button             $Abort = 1     EndSwitch EndFunc   ;==>_Event Func _Copy($sSource, $sDestination, $fReplace = False, $iFlags = 0, $sRoot = '')     Local $sPath, $sFile, $hSearch, $Percent, $Result, $Size, $State, $Error = -1     If Not $sRoot Then         $DirSize = DirGetSize($sSource)         $CurSize = 0     EndIf     $hSearch = FileFindFirstFile($sSource & $sRoot & '\*.*')     If $hSearch = -1 Then         Switch @error             Case 1 ; Folder is empty             Case Else                 Return SetError(-1, 0, 0)         EndSwitch     EndIf     While 1         $sFile = FileFindNextFile($hSearch)         If @error Then             FileClose($hSearch)             Return 1         EndIf         $sPath = $sRoot & '\' & $sFile         If @extended Then             GUICtrlSetData($Label1, $sDestination & $sPath)             If Not FileExists($sDestination & $sPath) Then                 If Not DirCreate($sDestination & $sPath) Then                     ExitLoop                 EndIf                 FileSetAttrib($sDestination & $sPath, '+' & StringReplace(FileGetAttrib($sSource & $sPath), 'D', ''))             EndIf             If Not _Copy($sSource, $sDestination, $fReplace, $iFlags, $sPath) Then                 $Error = @error                 ExitLoop             EndIf         Else             GUICtrlSetData($Label2, $sFile)             GUICtrlSetData($Progress2, 0)             $Size = FileGetSize($sSource & $sPath)             If @error Then                 ExitLoop             EndIf             Do                 If (Not $fReplace) And (FileExists($sDestination & $sPath)) Then                     $Result = MsgBox(35, '', $sDestination & $sPath & ' already exists.' & @CR & @CR & 'Do you want to replace it?', 0, $hForm)                     Switch $Result                         Case 2 ; "CANCEL"                             $Error = 1235 ; ERROR_REQUEST_ABORTED                             ExitLoop 2                         Case 7 ; "NO"                             ExitLoop                     EndSwitch                 EndIf                 If Not _Copy_CopyFile($sSource & $sPath, $sDestination & $sPath, $iFlags) Then                     ExitLoop 2                 EndIf                 While 1                     If $Abort Then                         _Copy_Abort()                     EndIf                     $State = _Copy_GetState()                     If $State[0] Then                         $Percent = Round($State[1] / $Size * 100)                         If GUICtrlRead($Progress2) <> $Percent Then                             GUICtrlSetData($Progress2, $Percent)                         EndIf                         $Percent = Round(($CurSize + $State[1]) / $DirSize * 100)                         If GUICtrlRead($Progress1) <> $Percent Then                             GUICtrlSetData($Progress1, $Percent)                         EndIf                     Else                         If Not $State[2] Then                             GUICtrlSetData($Progress2, 100)                         Else                             $Error = $State[2]                             ExitLoop 3                         EndIf                         ExitLoop 2                     EndIf                 WEnd                 If Not StringInStr(FileGetAttrib($sSource & $sPath), 'A') Then                     FileSetAttrib($sDestination & $sPath, '-A')                 EndIf             Until 1             $CurSize += $Size             $Percent = Round($CurSize / $DirSize * 100)             If GUICtrlRead($Progress1) <> $Percent Then                 GUICtrlSetData($Progress1, $Percent)             EndIf         EndIf     WEnd     FileClose($hSearch)     Return SetError($Error, 0, 0) EndFunc   ;==>_EnumFiles

Edited by Yashied, 07 November 2010 - 12:50 AM.


#4 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,165 posts

Posted 07 November 2010 - 08:22 AM

You rock.. Thanks for this UDF

Not much to add to this one m8 :graduated:, thanks a lot for the dll fun lately!

#5 Emiel Wieldraaijer

Emiel Wieldraaijer

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 651 posts

Posted 12 November 2010 - 06:58 PM

Hi Yashied,

I believe you should remove the following

If Not StringInStr(FileGetAttrib($sSource & $sPath), 'A') Then    FileSetAttrib($sDestination & $sPath, '-A') EndIf


Wiki Archive Bit


Best regards,

Emiel

Edited by Emiel Wieldraaijer, 12 November 2010 - 07:01 PM.

Best regards,Emiel WieldraaijerPosted Image

#6 Emiel Wieldraaijer

Emiel Wieldraaijer

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 651 posts

Posted 13 November 2010 - 04:16 PM

Another Example based on the recurvice folder copy example from Yashied

AutoIt         
#NoTrayIcon #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <UpDownConstants.au3> #include <EditConstants.au3> #include "Copy.au3" If Not _Copy_OpenDll() Then     MsgBox(16, '', 'Copy.dll not found.')     Exit EndIf Dim $Version = "1.0.0" Dim $Website = "<a href='http://www.autoitscript.com' class='bbc_url' title=''>http://www.autoitscript.com"</a> Dim $Menu[7], $Button[4], $Progress1, $Progress2, $Percent, $Size, $State, $Copy = 0 Dim $DirSize[3], $DirSizeAfter[4], $Max[4], $CurSize, $Abort = False Dim $Title = "Copy Folder" $Source = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Source", "") $Destination = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Destination", "") $Days = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Days", "7") $Current = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Current", "") $Erase = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Erase", "NO") $GUI = GUICreate($Title, 440, 390) $Menu[1] = GUICtrlCreateMenu("&File") $Menu[4] = GUICtrlCreateMenuItem("E&xit", $Menu[1]) $Menu[2] = GUICtrlCreateMenu("Options") $Menu[5] = GUICtrlCreateMenuItem("&Erase folder ", $Menu[2]) $Menu[3] = GUICtrlCreateMenu("&?") $Menu[6] = GUICtrlCreateMenuItem("Website &AutoItScripts", $Menu[3]) If $Erase = "YES" Then GUICtrlSetState($Menu[5], $GUI_Checked) GUICtrlCreateGroup("Source : ", 10, 20, 415, 55) $SourceInput = GUICtrlCreateInput("", 20, 40, 365, 20) GUICtrlSetState(-1, $GUI_Disable) GUICtrlSetData(-1, $Source) $Button[1] = GUICtrlCreateButton("...", 395, 40, 20, 20) GUICtrlSetTip(-1, "Select source folder", "", 0, 2) GUICtrlCreateGroup("Target : ", 10, 80, 415, 55) $DestinationInput = GUICtrlCreateInput("", 20, 100, 365, 20) GUICtrlSetState(-1, $GUI_Disable) GUICtrlSetData(-1, $Destination) $Button[2] = GUICtrlCreateButton("...", 395, 100, 20, 20) GUICtrlSetTip(-1, "Select target folder", "", 0, 2) GUICtrlCreateGroup("Status : ", 10, 140, 415, 175) GUICtrlCreateLabel("File...........................", 20, 160, 95, 20) $Label = GUICtrlCreateInput("", 120, 158, 295, 20) GUICtrlSetState(-1, $GUI_Disable) GUICtrlCreateLabel("Current...............................", 20, 180, 95, 20) $Progress2 = GUICtrlCreateProgress(120, 178, 295, 20) GUICtrlCreateLabel("Total.............................", 20, 200, 95, 20) $Progress1 = GUICtrlCreateProgress(120, 198, 295, 20) GUICtrlCreateLabel("Files..........................", 20, 240, 95, 20) $TotalFiles = GUICtrlCreateInput("", 120, 238, 110, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) GUICtrlCreateLabel("Folders..........................", 20, 260, 95, 20) $TotalFolders = GUICtrlCreateInput("", 120, 258, 110, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) GUICtrlCreateLabel("Size(MB)...................", 20, 280, 95, 20) $CurrentSize = GUICtrlCreateInput("", 120, 278, 110, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) $Last2 = GUICtrlCreateLabel("Last................................", 240, 240, 100, 20) GUICtrlSetTip(-1, "Last subfolder used for Backup", "", 0, 2) $Last = GUICtrlCreateInput("-", 345, 238, 70, 20, $SS_RIGHT) If $Current = "" Then     $Current = 1 ElseIf $Current = 1 Then     GUICtrlSetData($Last, $Days) Else     GUICtrlSetData($Last, $Current - 1) EndIf GUICtrlSetState(-1, $GUI_Disable) $Next2 = GUICtrlCreateLabel("Next...........................", 240, 260, 100, 20) GUICtrlSetTip(-1, "Next subfolder used for Backup", "", 0, 2) $Next = GUICtrlCreateInput($Current, 345, 258, 70, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) $Max[1] = GUICtrlCreateInput($Days, 345, 278, 70, 20, $ES_READONLY + $SS_RIGHT) $Max[2] = GUICtrlCreateLabel("Maximum........................", 240, 280, 100, 20) GUICtrlSetTip(-1, "Maximum subfolders used for Backup", "", 0, 2) $Max[3] = GUICtrlCreateUpdown($Max[1], 0x21) GUICtrlSetLimit(-1, 999, 2) $Button[3] = GUICtrlCreateButton("Copy", 340, 330, 80, 20) GUICtrlSetState(-1, $GUI_DEFBUTTON) GUISetState() _ReduceMemory() Func _ButtonControl($Value)     For $i = 1 To 3         GUICtrlSetState($Button[$i], $Value)     Next EndFunc   ;==>_ButtonControl While 1     $msg = GUIGetMsg()     If $msg = $GUI_EVENT_CLOSE Then _Terminate()     Switch $msg         Case -100 To 0             ContinueLoop         Case $msg = $GUI_EVENT_CLOSE             _Terminate()         Case $msg = $Menu[4]             _Terminate()         Case $Button[1]             $FolderSelect = FileSelectFolder("Select source folder", "", 3, GUICtrlRead($SourceInput))             If $FolderSelect <> "" Then                 GUICtrlSetData($SourceInput, $FolderSelect)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Source", $FolderSelect)                 $FolderInfo = DirGetSize($FolderSelect)             EndIf         Case $Button[2]             $FolderSelect = FileSelectFolder("Select target folder", "", 3, GUICtrlRead($DestinationInput))             If $FolderSelect <> "" Then                 GUICtrlSetData($DestinationInput, $FolderSelect)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Destination", $FolderSelect)             EndIf         Case $Button[3]             If GUICtrlRead($Button[3]) = "Abort" Then                 $Abort = 1                 GUICtrlSetData($Button[3], "Copy")             Else                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Days", GUICtrlRead($Max[1]))                 If GUICtrlRead($SourceInput) = "" Or GUICtrlRead($DestinationInput) = "" Then                     _ButtonControl($GUI_Disable)                     MsgBox(16, '', 'The source and destination must be specified.', 0, $GUI)                     _ButtonControl($GUI_Enable)                 ElseIf GUICtrlRead($SourceInput) = GUICtrlRead($DestinationInput) Then                     _ButtonControl($GUI_Disable)                     MsgBox(16, '', 'The source and destination must be different.', 0, $GUI)                     _ButtonControl($GUI_Enable)                 Else                     GUICtrlSetData($Progress1, 0)                     GUICtrlSetData($Button[3], "Abort")                     GUICtrlSetState($Button[1], $GUI_Disable)                     GUICtrlSetState($Button[2], $GUI_Disable)                     GUICtrlSetData($Next2, "Current............................")                     GUICtrlSetTip($Next2, "Current subfolder used for Backup", "", 0, 2)                     If $Erase = "YES" Then _Flush(GUICtrlRead($DestinationInput) & '\' & $Current)                     $TimeStart = TimerInit()                     $sFileCount = 0                     $sFolderCount = 0                     _CopyData(GUICtrlRead($SourceInput), GUICtrlRead($DestinationInput) & '\' & $Current, True)                     Switch @error                         Case 0                             $TimeEnd = Round(TimerDiff($TimeStart) / 1000)                             $DirSizeAfter = DirGetSize(GUICtrlRead($DestinationInput) & '\' & $Current, 1)                             GUICtrlSetState($Button[3], $GUI_Disable)                             MsgBox(64, '', 'Copied ' & $DirSizeAfter[1] & ' files successfully in ' & $TimeEnd & ' Seconds.', 0, $GUI)                         Case 1235 ; ERROR_REQUEST_ABORTED                             $TimeEnd = Round(TimerDiff($TimeStart) / 1000)                             GUICtrlSetState($Button[3], $GUI_Disable)                             MsgBox(16, '', 'Copy was aborted by user.', 0, $GUI)                         Case Else                             $TimeEnd = Round(TimerDiff($TimeStart) / 1000)                             GUICtrlSetState($Button[3], $GUI_Disable)                             MsgBox(16, '', 'No files were copied. ' & @CR & @CR & @error, 0, $GUI)                     EndSwitch                     GUICtrlSetData($Next2, "Next...............")                     GUICtrlSetTip(-1, "Next subfolder used for Backup", "", 0, 2)                     $Current = $Current + 1                     If $Current > $Days Then $Current = 1                     IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Current", $Current)                     If $Current - 1 = 0 Then                         GUICtrlSetData($Last, $Days)                     Else                         GUICtrlSetData($Last, $Current - 1)                     EndIf                     GUICtrlSetData($Next, $Current)                     GUICtrlSetData($Button[3], "Copy")                     _ButtonControl($GUI_Enable)                 EndIf             EndIf         Case $Menu[6]             ShellExecute($Website)         Case $Menu[5]             If BitAND(GUICtrlRead($Menu[5]), $GUI_Checked) = $GUI_Checked Then                 GUICtrlSetState($Menu[5], $GUI_UNChecked)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Erase", "NO")                 $Erase = "NO"             Else                 GUICtrlSetState($Menu[5], $GUI_Checked)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Erase", "YES")                 $Erase = "YES"             EndIf     EndSwitch WEnd ;==> Func _CopyData($sSource, $sDestination, $fReplace = False, $iFlags = 0, $sRoot = '')     Local $sPath, $sFile, $hSearch, $Percent, $Result, $Size, $State, $Error = -1     If Not $sRoot Then         $DirSize = DirGetSize($sSource, 1)         $CurSize = 0     EndIf     $hSearch = FileFindFirstFile($sSource & $sRoot & '\*.*')     If $hSearch = -1 Then         Switch @error             Case 1 ; Folder is empty             Case Else                 Return SetError(-1, 0, 0)         EndSwitch     EndIf     While 1         $sFile = FileFindNextFile($hSearch)         If @error Then             FileClose($hSearch)             Return 1         EndIf         $sPath = $sRoot & '\' & $sFile         If @extended Then ; folder             $sFolderCount = $sFolderCount + 1             GUICtrlSetData($TotalFolders, $sFolderCount & '/' & $DirSize[2])             If Not FileExists($sDestination & $sPath) Then                 If Not DirCreate($sDestination & $sPath) Then                     ExitLoop                 EndIf                 FileSetAttrib($sDestination & $sPath, '+' & StringReplace(FileGetAttrib($sSource & $sPath), 'D', ''))             EndIf             If Not _CopyData($sSource, $sDestination, $fReplace, $iFlags, $sPath) Then                 $Error = @error                 ExitLoop             EndIf         Else ; file             GUICtrlSetData($Label, $sFile)             $sFileCount = $sFileCount + 1             GUICtrlSetData($TotalFiles, $sFileCount & '/' & $DirSize[1])             GUICtrlSetData($Progress2, 0)             $Size = FileGetSize($sSource & $sPath)             If @error Then                 ExitLoop             EndIf             Do                 If (Not $fReplace) And (FileExists($sDestination & $sPath)) Then ; FileExists                     $Result = MsgBox(35, '', $sDestination & $sPath & ' already exists.' & @CR & @CR & 'Do you want to replace it?', 0, $GUI)                     Switch $Result                         Case 2 ; "CANCEL"                             $Error = 1235 ; ERROR_REQUEST_ABORTED                             ExitLoop 2                         Case 7 ; "NO"                             ExitLoop                     EndSwitch                 EndIf                 If Not _Copy_CopyFile($sSource & $sPath, $sDestination & $sPath, $iFlags) Then                     ExitLoop 2                 EndIf                 While 1                     $Msg2 = GUIGetMsg()                     If $Msg2 = $GUI_EVENT_CLOSE Then _Terminate()                     Select                         Case $Msg2 = $Button[3]                             $Abort = 1                             GUICtrlSetData($Progress1, 0)                             GUICtrlSetData($Progress2, 0)                         Case $Msg2 = $GUI_EVENT_CLOSE                             _Terminate()                         Case $Msg2 = $Menu[4]                             _Terminate()                         Case $Msg2 = $Menu[6]                             ShellExecute($Website)                     EndSelect                     If $Abort Then                         _Copy_Abort()                         $Abort = False                     EndIf                     $State = _Copy_GetState()                     If $State[0] Then                         $Percent = Round($State[1] / $Size * 100)                         If GUICtrlRead($Progress2) <> $Percent Then                             GUICtrlSetData($Progress2, $Percent)                         EndIf                         $Percent = Round(($CurSize + $State[1]) / $DirSize[0] * 100)                         If GUICtrlRead($Progress1) <> $Percent Then                             GUICtrlSetData($Progress1, $Percent)                         EndIf                     Else                         If Not $State[2] Then                             GUICtrlSetData($Progress2, 100)                         Else                             $Error = $State[2]                             ExitLoop 3                         EndIf                         ExitLoop 2                     EndIf                 WEnd                 ;If Not StringInStr(FileGetAttrib($sSource & $sPath), 'A') Then                 ;   FileSetAttrib($sDestination & '\' & $Current & $sPath, '-A')                 ;EndIf             Until 1             $CurSize += $Size             $Percent = Round($CurSize / $DirSize[0] * 100)             GUICtrlSetData($CurrentSize, Round($CurSize / 1048576, 0) & '/' & Round($DirSize[0] / 1048576, 0))             If GUICtrlRead($Progress1) <> $Percent Then                 GUICtrlSetData($Progress1, $Percent)             EndIf             FileSetAttrib($sDestination & '\' & $Current & $sPath, '+A')         EndIf     WEnd     FileClose($hSearch)     Return SetError($Error, 0, 0) EndFunc   ;==>_CopyData Func _Terminate()     IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Days", GUICtrlRead($Max[1]))     _Copy_Abort()     _Copy_CloseDll()     Exit EndFunc   ;==>_Terminate Func _ReduceMemory($i_PID = -1)     If $i_PID <> -1 Then         Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)         Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])         DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])     Else         Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)     EndIf     Return $ai_Return[0] EndFunc   ;==>_ReduceMemory Func _Flush($folder)     FileSetAttrib($folder & "\*.*", "-RSH", 1)     Local $search, $file, $attrib     $search = FileFindFirstFile($folder & "\*.*")     If $search <> -1 Then         While 1             $file = FileFindNextFile($search)             If @error Then ExitLoop             $attrib = FileGetAttrib($folder & "\" & $file)             If StringInStr($attrib, "D") Then                 DirRemove($folder & "\" & $file, 1)             Else                 FileDelete($folder & "\" & $file)             EndIf         WEnd     EndIf EndFunc   ;==>_Flush

Edited by Emiel Wieldraaijer, 13 November 2010 - 04:20 PM.

Best regards,Emiel WieldraaijerPosted Image

#7 leomoon

leomoon

    Adventurer

  • Active Members
  • PipPip
  • 114 posts

Posted 21 November 2010 - 11:06 AM

AWESOME script.

Is there anyway to have multiple source and multiple destination? I tried for an hour with no luck!

#8 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 21 November 2010 - 12:12 PM

AWESOME script.

Is there anyway to have multiple source and multiple destination? I tried for an hour with no luck!

Example 2 from first post.

Edited by Yashied, 21 November 2010 - 12:12 PM.


#9 wuruoyu

wuruoyu

    Seeker

  • Active Members
  • 6 posts

Posted 21 November 2010 - 10:23 PM

Like leomoon said, awesome script! Yashied

Is there a way to copy folder to folder from multiple path $source that is combine into an array list.

ex.
$arrayItem01 = "C:\1"
$arrayItem02 = "C:\2"
_arrayAdd($sFolders, $arrayItem01)
_arrayAdd($sFolders, $arrayItem02)

sFolders as the source folder. and display the total progress properly.

Thanks in advanced.

#10 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 22 November 2010 - 02:56 AM

@wuruoyu
That is not a reasonable UDF request. Write your own wrapper function to utilize this UDF to accomplish your goal.

#11 wuruoyu

wuruoyu

    Seeker

  • Active Members
  • 6 posts

Posted 22 November 2010 - 03:04 AM

@wraithdu
I see. but forgot to mention. I am asking the UDF maker( Yashied ). Maybe this is too difficult everybody else other than Yashied. :-)

#12 James

James

    jbrooksuk

  • MVPs
  • 9,470 posts

Posted 22 November 2010 - 10:02 AM

@wraithdu
I see. but forgot to mention. I am asking the UDF maker( Yashied ). Maybe this is too difficult everybody else other than Yashied. :-)


No, it's not reasonable for part of the UDF.

The idea of a UDF is to allow developers to write their own wrappers around the functions provided. It's up to you to use Copy.au3 to make it act like you want it to.

Implementing your idea directly into the source would make it act very strictly, stopping Yashied's examples from working how they do and breaking any scripts that rely on it how it works currently.

Your ignorance to this fact makes you even more stupid than not backing away from wraithdu's comment when he fully explained why this would not be done.

#13 paule

paule

    Seeker

  • Active Members
  • 14 posts

Posted 22 November 2010 - 12:16 PM

@yashied

Only work on 32 Bit.

I have a German 64Bit Windows 7 Ultimate OS

$__cpDll = DllOpen($sDll)
If $__cpDll = -1 Then
Return SetError(1, 0, 0)
EndIf

On 64Bit the result $__cpDll is always -1.
XP 32Bit is ok $__cpDll=1

#14 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 22 November 2010 - 07:03 PM

@paule
I guess the DLL for this UDF is a 32-bit DLL. Just compile your script as a 32-bit executable and you'll be fine. 64-bit executables cannot load 32-bit DLLs and vice-versa.

Edited by wraithdu, 22 November 2010 - 07:03 PM.


#15 freMea

freMea

    Seeker

  • Active Members
  • 11 posts

Posted 22 November 2010 - 09:13 PM

Another Example based on the recurvice folder copy example from Yashied

AutoIt         
#NoTrayIcon #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <UpDownConstants.au3> #include <EditConstants.au3> #include "Copy.au3" If Not _Copy_OpenDll() Then     MsgBox(16, '', 'Copy.dll not found.')     Exit EndIf Dim $Version = "1.0.0" Dim $Website = "http://www.autoitscript.com" Dim $Menu[7], $Button[4], $Progress1, $Progress2, $Percent, $Size, $State, $Copy = 0 Dim $DirSize[3], $DirSizeAfter[4], $Max[4], $CurSize, $Abort = False Dim $Title = "Copy Folder" $Source = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Source", "") $Destination = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Destination", "") $Days = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Days", "7") $Current = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Current", "") $Erase = IniRead(@ScriptDir & "\CFBackup.ini", "Settings", "Erase", "NO") $GUI = GUICreate($Title, 440, 390) $Menu[1] = GUICtrlCreateMenu("&File") $Menu[4] = GUICtrlCreateMenuItem("E&xit", $Menu[1]) $Menu[2] = GUICtrlCreateMenu("Options") $Menu[5] = GUICtrlCreateMenuItem("&Erase folder ", $Menu[2]) $Menu[3] = GUICtrlCreateMenu("&?") $Menu[6] = GUICtrlCreateMenuItem("Website &AutoItScripts", $Menu[3]) If $Erase = "YES" Then GUICtrlSetState($Menu[5], $GUI_Checked) GUICtrlCreateGroup("Source : ", 10, 20, 415, 55) $SourceInput = GUICtrlCreateInput("", 20, 40, 365, 20) GUICtrlSetState(-1, $GUI_Disable) GUICtrlSetData(-1, $Source) $Button[1] = GUICtrlCreateButton("...", 395, 40, 20, 20) GUICtrlSetTip(-1, "Select source folder", "", 0, 2) GUICtrlCreateGroup("Target : ", 10, 80, 415, 55) $DestinationInput = GUICtrlCreateInput("", 20, 100, 365, 20) GUICtrlSetState(-1, $GUI_Disable) GUICtrlSetData(-1, $Destination) $Button[2] = GUICtrlCreateButton("...", 395, 100, 20, 20) GUICtrlSetTip(-1, "Select target folder", "", 0, 2) GUICtrlCreateGroup("Status : ", 10, 140, 415, 175) GUICtrlCreateLabel("File...........................", 20, 160, 95, 20) $Label = GUICtrlCreateInput("", 120, 158, 295, 20) GUICtrlSetState(-1, $GUI_Disable) GUICtrlCreateLabel("Current...............................", 20, 180, 95, 20) $Progress2 = GUICtrlCreateProgress(120, 178, 295, 20) GUICtrlCreateLabel("Total.............................", 20, 200, 95, 20) $Progress1 = GUICtrlCreateProgress(120, 198, 295, 20) GUICtrlCreateLabel("Files..........................", 20, 240, 95, 20) $TotalFiles = GUICtrlCreateInput("", 120, 238, 110, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) GUICtrlCreateLabel("Folders..........................", 20, 260, 95, 20) $TotalFolders = GUICtrlCreateInput("", 120, 258, 110, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) GUICtrlCreateLabel("Size(MB)...................", 20, 280, 95, 20) $CurrentSize = GUICtrlCreateInput("", 120, 278, 110, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) $Last2 = GUICtrlCreateLabel("Last................................", 240, 240, 100, 20) GUICtrlSetTip(-1, "Last subfolder used for Backup", "", 0, 2) $Last = GUICtrlCreateInput("-", 345, 238, 70, 20, $SS_RIGHT) If $Current = "" Then     $Current = 1 ElseIf $Current = 1 Then     GUICtrlSetData($Last, $Days) Else     GUICtrlSetData($Last, $Current - 1) EndIf GUICtrlSetState(-1, $GUI_Disable) $Next2 = GUICtrlCreateLabel("Next...........................", 240, 260, 100, 20) GUICtrlSetTip(-1, "Next subfolder used for Backup", "", 0, 2) $Next = GUICtrlCreateInput($Current, 345, 258, 70, 20, $SS_RIGHT) GUICtrlSetState(-1, $GUI_Disable) $Max[1] = GUICtrlCreateInput($Days, 345, 278, 70, 20, $ES_READONLY + $SS_RIGHT) $Max[2] = GUICtrlCreateLabel("Maximum........................", 240, 280, 100, 20) GUICtrlSetTip(-1, "Maximum subfolders used for Backup", "", 0, 2) $Max[3] = GUICtrlCreateUpdown($Max[1], 0x21) GUICtrlSetLimit(-1, 999, 2) $Button[3] = GUICtrlCreateButton("Copy", 340, 330, 80, 20) GUICtrlSetState(-1, $GUI_DEFBUTTON) GUISetState() _ReduceMemory() Func _ButtonControl($Value)     For $i = 1 To 3         GUICtrlSetState($Button[$i], $Value)     Next EndFunc   ;==>_ButtonControl While 1     $msg = GUIGetMsg()     If $msg = $GUI_EVENT_CLOSE Then _Terminate()     Switch $msg         Case -100 To 0             ContinueLoop         Case $msg = $GUI_EVENT_CLOSE             _Terminate()         Case $msg = $Menu[4]             _Terminate()         Case $Button[1]             $FolderSelect = FileSelectFolder("Select source folder", "", 3, GUICtrlRead($SourceInput))             If $FolderSelect <> "" Then                 GUICtrlSetData($SourceInput, $FolderSelect)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Source", $FolderSelect)                 $FolderInfo = DirGetSize($FolderSelect)             EndIf         Case $Button[2]             $FolderSelect = FileSelectFolder("Select target folder", "", 3, GUICtrlRead($DestinationInput))             If $FolderSelect <> "" Then                 GUICtrlSetData($DestinationInput, $FolderSelect)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Destination", $FolderSelect)             EndIf         Case $Button[3]             If GUICtrlRead($Button[3]) = "Abort" Then                 $Abort = 1                 GUICtrlSetData($Button[3], "Copy")             Else                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Days", GUICtrlRead($Max[1]))                 If GUICtrlRead($SourceInput) = "" Or GUICtrlRead($DestinationInput) = "" Then                     _ButtonControl($GUI_Disable)                     MsgBox(16, '', 'The source and destination must be specified.', 0, $GUI)                     _ButtonControl($GUI_Enable)                 ElseIf GUICtrlRead($SourceInput) = GUICtrlRead($DestinationInput) Then                     _ButtonControl($GUI_Disable)                     MsgBox(16, '', 'The source and destination must be different.', 0, $GUI)                     _ButtonControl($GUI_Enable)                 Else                     GUICtrlSetData($Progress1, 0)                     GUICtrlSetData($Button[3], "Abort")                     GUICtrlSetState($Button[1], $GUI_Disable)                     GUICtrlSetState($Button[2], $GUI_Disable)                     GUICtrlSetData($Next2, "Current............................")                     GUICtrlSetTip($Next2, "Current subfolder used for Backup", "", 0, 2)                     If $Erase = "YES" Then _Flush(GUICtrlRead($DestinationInput) & '\' & $Current)                     $TimeStart = TimerInit()                     $sFileCount = 0                     $sFolderCount = 0                     _CopyData(GUICtrlRead($SourceInput), GUICtrlRead($DestinationInput) & '\' & $Current, True)                     Switch @error                         Case 0                             $TimeEnd = Round(TimerDiff($TimeStart) / 1000)                             $DirSizeAfter = DirGetSize(GUICtrlRead($DestinationInput) & '\' & $Current, 1)                             GUICtrlSetState($Button[3], $GUI_Disable)                             MsgBox(64, '', 'Copied ' & $DirSizeAfter[1] & ' files successfully in ' & $TimeEnd & ' Seconds.', 0, $GUI)                         Case 1235 ; ERROR_REQUEST_ABORTED                             $TimeEnd = Round(TimerDiff($TimeStart) / 1000)                             GUICtrlSetState($Button[3], $GUI_Disable)                             MsgBox(16, '', 'Copy was aborted by user.', 0, $GUI)                         Case Else                             $TimeEnd = Round(TimerDiff($TimeStart) / 1000)                             GUICtrlSetState($Button[3], $GUI_Disable)                             MsgBox(16, '', 'No files were copied. ' & @CR & @CR & @error, 0, $GUI)                     EndSwitch                     GUICtrlSetData($Next2, "Next...............")                     GUICtrlSetTip(-1, "Next subfolder used for Backup", "", 0, 2)                     $Current = $Current + 1                     If $Current > $Days Then $Current = 1                     IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Current", $Current)                     If $Current - 1 = 0 Then                         GUICtrlSetData($Last, $Days)                     Else                         GUICtrlSetData($Last, $Current - 1)                     EndIf                     GUICtrlSetData($Next, $Current)                     GUICtrlSetData($Button[3], "Copy")                     _ButtonControl($GUI_Enable)                 EndIf             EndIf         Case $Menu[6]             ShellExecute($Website)         Case $Menu[5]             If BitAND(GUICtrlRead($Menu[5]), $GUI_Checked) = $GUI_Checked Then                 GUICtrlSetState($Menu[5], $GUI_UNChecked)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Erase", "NO")                 $Erase = "NO"             Else                 GUICtrlSetState($Menu[5], $GUI_Checked)                 IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Erase", "YES")                 $Erase = "YES"             EndIf     EndSwitch WEnd ;==> Func _CopyData($sSource, $sDestination, $fReplace = False, $iFlags = 0, $sRoot = '')     Local $sPath, $sFile, $hSearch, $Percent, $Result, $Size, $State, $Error = -1     If Not $sRoot Then         $DirSize = DirGetSize($sSource, 1)         $CurSize = 0     EndIf     $hSearch = FileFindFirstFile($sSource & $sRoot & '\*.*')     If $hSearch = -1 Then         Switch @error             Case 1 ; Folder is empty             Case Else                 Return SetError(-1, 0, 0)         EndSwitch     EndIf     While 1         $sFile = FileFindNextFile($hSearch)         If @error Then             FileClose($hSearch)             Return 1         EndIf         $sPath = $sRoot & '\' & $sFile         If @extended Then ; folder             $sFolderCount = $sFolderCount + 1             GUICtrlSetData($TotalFolders, $sFolderCount & '/' & $DirSize[2])             If Not FileExists($sDestination & $sPath) Then                 If Not DirCreate($sDestination & $sPath) Then                     ExitLoop                 EndIf                 FileSetAttrib($sDestination & $sPath, '+' & StringReplace(FileGetAttrib($sSource & $sPath), 'D', ''))             EndIf             If Not _CopyData($sSource, $sDestination, $fReplace, $iFlags, $sPath) Then                 $Error = @error                 ExitLoop             EndIf         Else ; file             GUICtrlSetData($Label, $sFile)             $sFileCount = $sFileCount + 1             GUICtrlSetData($TotalFiles, $sFileCount & '/' & $DirSize[1])             GUICtrlSetData($Progress2, 0)             $Size = FileGetSize($sSource & $sPath)             If @error Then                 ExitLoop             EndIf             Do                 If (Not $fReplace) And (FileExists($sDestination & $sPath)) Then ; FileExists                     $Result = MsgBox(35, '', $sDestination & $sPath & ' already exists.' & @CR & @CR & 'Do you want to replace it?', 0, $GUI)                     Switch $Result                         Case 2 ; "CANCEL"                             $Error = 1235 ; ERROR_REQUEST_ABORTED                             ExitLoop 2                         Case 7 ; "NO"                             ExitLoop                     EndSwitch                 EndIf                 If Not _Copy_CopyFile($sSource & $sPath, $sDestination & $sPath, $iFlags) Then                     ExitLoop 2                 EndIf                 While 1                     $Msg2 = GUIGetMsg()                     If $Msg2 = $GUI_EVENT_CLOSE Then _Terminate()                     Select                         Case $Msg2 = $Button[3]                             $Abort = 1                             GUICtrlSetData($Progress1, 0)                             GUICtrlSetData($Progress2, 0)                         Case $Msg2 = $GUI_EVENT_CLOSE                             _Terminate()                         Case $Msg2 = $Menu[4]                             _Terminate()                         Case $Msg2 = $Menu[6]                             ShellExecute($Website)                     EndSelect                     If $Abort Then                         _Copy_Abort()                         $Abort = False                     EndIf                     $State = _Copy_GetState()                     If $State[0] Then                         $Percent = Round($State[1] / $Size * 100)                         If GUICtrlRead($Progress2) <> $Percent Then                             GUICtrlSetData($Progress2, $Percent)                         EndIf                         $Percent = Round(($CurSize + $State[1]) / $DirSize[0] * 100)                         If GUICtrlRead($Progress1) <> $Percent Then                             GUICtrlSetData($Progress1, $Percent)                         EndIf                     Else                         If Not $State[2] Then                             GUICtrlSetData($Progress2, 100)                         Else                             $Error = $State[2]                             ExitLoop 3                         EndIf                         ExitLoop 2                     EndIf                 WEnd                 ;If Not StringInStr(FileGetAttrib($sSource & $sPath), 'A') Then                 ;   FileSetAttrib($sDestination & '\' & $Current & $sPath, '-A')                 ;EndIf             Until 1             $CurSize += $Size             $Percent = Round($CurSize / $DirSize[0] * 100)             GUICtrlSetData($CurrentSize, Round($CurSize / 1048576, 0) & '/' & Round($DirSize[0] / 1048576, 0))             If GUICtrlRead($Progress1) <> $Percent Then                 GUICtrlSetData($Progress1, $Percent)             EndIf             FileSetAttrib($sDestination & '\' & $Current & $sPath, '+A')         EndIf     WEnd     FileClose($hSearch)     Return SetError($Error, 0, 0) EndFunc   ;==>_CopyData Func _Terminate()     IniWrite(@ScriptDir & "\CFBackup.ini", "Settings", "Days", GUICtrlRead($Max[1]))     _Copy_Abort()     _Copy_CloseDll()     Exit EndFunc   ;==>_Terminate Func _ReduceMemory($i_PID = -1)     If $i_PID <> -1 Then         Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)         Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])         DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])     Else         Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)     EndIf     Return $ai_Return[0] EndFunc   ;==>_ReduceMemory Func _Flush($folder)     FileSetAttrib($folder & "\*.*", "-RSH", 1)     Local $search, $file, $attrib     $search = FileFindFirstFile($folder & "\*.*")     If $search <> -1 Then         While 1             $file = FileFindNextFile($search)             If @error Then ExitLoop             $attrib = FileGetAttrib($folder & "\" & $file)             If StringInStr($attrib, "D") Then                 DirRemove($folder & "\" & $file, 1)             Else                 FileDelete($folder & "\" & $file)             EndIf         WEnd     EndIf EndFunc   ;==>_Flush

You're example doesn't work at home (XP PRO SP3, AutoIt v3.3.6.1) "No files were copied".

The source folder contains 5 files and the target folder is empty.

What did I miss?
  • ESATU likes this
  • AutoIt 3.3.8.1
  • Win XP PRO SP3

#16 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 22 November 2010 - 11:28 PM

The short bus maybe? How is anyone supposed to try to help you when you've provided absolutely no information that is even slightly useful?

#17 freMea

freMea

    Seeker

  • Active Members
  • 11 posts

Posted 23 November 2010 - 12:54 AM

The short bus maybe? How is anyone supposed to try to help you when you've provided absolutely no information that is even slightly useful?


Sorry, I'm a noob and I don't know yet what I can say more about it. But, it would be helpful if I was just told the script I mention above works for someone or not.

Cheers :graduated:
  • AutoIt 3.3.8.1
  • Win XP PRO SP3

#18 wuruoyu

wuruoyu

    Seeker

  • Active Members
  • 6 posts

Posted 23 November 2010 - 01:11 AM

wow, cannot believe some people here are very impatient, rarher than write 100 words to express your own point of view. for honest people would just say i dont know or a good programmer would instead posting something more useful to help people on this forum. isn't that the whole point. and thanks you. i solved my array problem. :-)

Edited by wuruoyu, 23 November 2010 - 01:15 AM.


#19 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 23 November 2010 - 05:14 AM

Why don't you save your own 100 words and come up with a solution to your own problem? This forum is about helping people, not spoon feeding them some code they wouldn't understand anyway. Most of the people commenting in this thread are more than capable of solving your problem in 10 minutes. But it's your problem. What would you learn if we did it for you? If you've solved your problem already, then great, hopefully you've learned something along the way. Otherwise post something that shows you've at least put in some effort and you're more likely to get a helpful response.

@freMea
Odds are if the example was posted, then it at least works for him. If you're so much a noob that you are unable to provide relevant information regarding your errors, then maybe you're not ready for this UDF. Just saying...



... and yes, I'm impatient today.

Edited by wraithdu, 23 November 2010 - 05:15 AM.


#20 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 23 November 2010 - 07:38 AM

@paule

Copy_x64.dll or download it again from the first post. Use the following:

_Copy_OpenDll(@ScriptDir & '\Copy_x64.dll')

Edited by Yashied, 23 November 2010 - 07:39 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users