Sign in to follow this  
Followers 0
radienergos

Progress Copy Script

11 posts in this topic

#1 ·  Posted (edited)

hiiii , can anyone tell me how can i stop this script from executing?

CODE
;use ProgressCopy(Source,Destination, 1 to use multi colour ,"Attributes", 1 for Overwrite files)

#include <GUIConstants.au3>

ProgressCopy("D:\Images", "d:\Backup\",1)

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get original DirSize and set up Gui

If $Run1 = 0 Then

Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist

$source = $current

If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)

If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"

$tosearch = $current

$Overall = DirGetSize($tosearch, 1)

$OverallQty = $Overall[1]

Global Const $PrCopyGui = GUICreate("Copying Files", 420, 100, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

$Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)

$progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)

GUICtrlSetColor(-1, 32250)

$Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)

$progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)

$Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)

GUISetFont(10, 600)

;$Progress2Text2 = GUICtrlCreateLabel("", 150, 62, 400, 20)

GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above

GUISetState(@SW_SHOW)

GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)

$Run1 = 1

EndIf

$Size = DirGetSize($current, 3)

$Qty = $Size[1]

Local $search = FileFindFirstFile($current & "\*.*")

While 1

Dim $file = FileFindNextFile($search)

If @error Or StringLen($file) < 1 Then ExitLoop

If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

$Qty -= 1

$LocalPercent = 100 - (($Qty / $Size[1]) * 100)

$OverallQty -= 1

$overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)

GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")

GUICtrlSetData($progressbar1, $overallpercent)

GUICtrlSetData($progressbar2, $LocalPercent)

GUICtrlSetData($Progress2Text, "Copying File " & $file)

If $useMultiColour then

GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))

GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))

EndIf

FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)

FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)

EndIf

If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)

FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)

GUICtrlSetData($Progress1Text, $current & "\" & $file)

ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)

EndIf

WEnd

FileClose($search)

;when overall percent = 100 set end gui text, delete gui and reset run1 to 0

If $overallpercent = 100 Then

GUICtrlSetData($Progress0Text, "Total Progress 100% completed")

GUICtrlSetData($progressbar1, 100)

GUICtrlSetData($progressbar2, 100)

GUICtrlSetData($Progress2Text, "Done!")

Sleep(2000)

GUIDelete($PRCopyGui)

$Run1 = 0

EndIf

EndFunc ;==>ProgressCopy

Func _ChangeColour($start)

$Redness = Int(255 - ($start / 100 * 512))

If $Redness < 0 Then $Redness = 0

$Greeness = Int(($start / 100 * 512) - 257)

If $Greeness < 0 Then $Greeness = 0

$Blueness = Int(255 - ($Redness + $Greeness))

Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness

EndFunc

i just want to create 2 buttons , START and stop , the problem is that i can't figure how i can stop the copying

thanks in advance

Edited by radienergos

Share this post


Link to post
Share on other sites



Might think about HotKeySet() and look at the example. It pauses the execution of a script.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

hmmm yeah if i use hotkeyset it works , but how can i use a button instead of a hotkeyset ? and actually i want to stop the progress copy , no to pause it

Share this post


Link to post
Share on other sites

because (after a big break :)) i didn't find a way yet to stop it , can someone help me with this ?

thanks in advance

(hotkeyset works, but i want a button )

Share this post


Link to post
Share on other sites

I was wondering on this myself. Having a key do what a hotkeyset would do.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Nice script :)

;use ProgressCopy(Source,Destination, 1 to use multi colour ,"Attributes", 1 for Overwrite files)
#include <GUIConstants.au3>
ProgressCopy("D:\Images", "d:\Backup\",1)


Func ProgressCopy($current, $destination,  $UseMultiColour=0, $attrib = "-R", $overwrite = 1 ,$Run1 = 0 )
    
;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
        Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text,  $LocalPercent
        DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
        If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
        $source = $current
        If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
        If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
        $tosearch = $current
        $Overall = DirGetSize($tosearch, 1)
        $OverallQty = $Overall[1]
        Global Const $PrCopyGui = GUICreate("Copying Files", 420, 100, -1, -1, -1, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
        $Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
        GUICtrlSetColor(-1, 32250)
        $Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
        $Progress2Text = GUICtrlCreateLabel("", 10, 82, 360, 20, $SS_LEFTNOWORDWRAP); *******changed the size of this label too*******
        GUISetFont(10, 600)
        GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
;*****************************************************************
        Global $cButton = GuiCtrlCreateButton("Cancel",380,85,40,15)
        GuiCtrlSetFont(-1,7,300)
;*****************************************************************
        GUISetState(@SW_SHOW)
        GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
        $Run1 = 1
    EndIf
    
    $Size = DirGetSize($current, 3)
    $Qty = $Size[1]
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
;***********************************************
        If GuiGetMsg() = $cButton then exit
;***********************************************
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            $Qty -= 1
            $LocalPercent = 100 - (($Qty / $Size[1]) * 100)
            $OverallQty -= 1
            $overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
            GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")
            GUICtrlSetData($progressbar1, $overallpercent)
            GUICtrlSetData($progressbar2, $LocalPercent)
            GUICtrlSetData($Progress2Text, "Copying File " & $file)
            
            If $useMultiColour then
                GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
                GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
            EndIf
            
            FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
            GUICtrlSetData($Progress1Text, $current & "\" & $file)
            ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)
        EndIf
    WEnd
    FileClose($search)
;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
    If $overallpercent = 100 Then
        GUICtrlSetData($Progress0Text, "Total Progress 100% completed")
        GUICtrlSetData($progressbar1, 100)
        GUICtrlSetData($progressbar2, 100)
        GUICtrlSetData($Progress2Text, "Done!")
        Sleep(2000)
        GUIDelete($PRCopyGui)
        $Run1 = 0
    EndIf
EndFunc;==>ProgressCopy

Func _ChangeColour($start)
    
    $Redness = Int(255 - ($start  / 100 * 512))
    If $Redness < 0 Then $Redness = 0
        
    $Greeness = Int(($start  / 100 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0
        
    $Blueness = Int(255 - ($Redness + $Greeness))
    
    Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness

EndFunc
Edited by ChrisL

Share this post


Link to post
Share on other sites

thanks for the reply,

well i just noticed that this code was old :) , now im trying to use this code in another gui

the problem is that i do something wrong and i can't click on the cancel button while the progresscopy runs

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

thanks for the reply,

well i just noticed that this code was old :) , now im trying to use this code in another gui

the problem is that i do something wrong and i can't click on the cancel button while the progresscopy runs

You'd have 2 choices more than likely since we don't have multithreading.

1. Using AdlibEnable() before the function /AdlibDisable() after the function to capture the GUIGetMsg() forcing you to make global variables.

2. Make the function into a seperate script that information can be passed via $cmdline[n]'s and use /AutoIt3ExecuteScript, this is the method I usually take, because I can kill it at anytime with a simple processclose or a hotkey I set in it.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

yeah , i try to do the whole thing into one program because i can't make a good looking transparent window for the program which use the progress copy (is there any way to lock the position of the gui except the $ws_disabled ??? )

thanks for the replies

Share this post


Link to post
Share on other sites

Instead of FileCopy() you must use your own _UDF for copying file.

It may use APIFileReadWrite.au3 UDF:

Func _APIFileOpen( $szFile )
Func _APIFileRead( $hFile, $nBytes, $Option=0 )
Func _APIFileWrite( $hFile, $szData, $Option=0 )
Func _APIFileClose( $hFile )

_APIFileRead() & _APIFileWrite() will be in While loop so you can pause inside half of copy of file.

Share this post


Link to post
Share on other sites

Or instead of using Filecopy use Run() function and xcopy.

Global $Pid

HotKeySet("{ESC}", "_KillProcess")

Func _KillProcess()
    Local $iMsgBoxAnswer    
    If Not ProcessExists($PID) Then Return
    $iMsgBoxAnswer = MsgBox(52,"Warning...","Are you sure, you want to stop copy process?")
    If $iMsgBoxAnswer == 6 Then ProcessClose($PID)      
EndFunc
oÝ÷ Ø(ZºÚ"µÍ[PÛÜJ  ÌÍØÝ[   [È ][ÝÉÌLÉ][ÝÈ   [È ÌÍÙ[K    ÌÍÙÝ[][Û   [ÈÝ[Õ[SY
    ÌÍØÝ[Ý[Ó[ ÌÍÜÛÝÙJJH [È ][ÝÉÌLÉ][ÝÈ   [È ÌÍÙ[K    ÌÍÛÝÜ]JBoÝ÷ Ùú+jëh×6$PID = Run(@ComSpec & ' /c xcopy "'& $current & '\' & $file & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" /g /h /r /y /z', @TempDir, @SW_HIDE)

While ProcessExists($PID)
    Sleep(50)
WEnd

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0