Jump to content

Recommended Posts

Hi,

I working on a simple dir copy script, but I've 2 questions about it.

1. I want copy all files to the root, and every file that exist must me overwrite, how must I do this?

(I has searching on this forum but I can't find that work.)

2. I now how onprogress() work with download files from the internet, but how must I do this with dircopy?

I now that you must have the size of the dir and the copy speed, but what is the copy speed?

Anyway thanks for reading.

YoseMite

Link to post
Share on other sites

Hi,

I working on a simple dir copy script, but I've 2 questions about it.

1. I want copy all files to the root, and every file that exist must me overwrite, how must I do this?

(I has searching on this forum but I can't find that work.)

2. I now how onprogress() work with download files from the internet, but how must I do this with dircopy?

I now that you must have the size of the dir and the copy speed, but what is the copy speed?

Anyway thanks for reading.

YoseMite

Answer to part 1, straight from help files.

DirCopy("C:\My Documents", "C:\Backups\MyDocs", 1)


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to post
Share on other sites

ah al right...

I see that question 1 works...

Allright I explain 2nd question.

You have a folder:

C:\dir

With different files and folders on it. (50MB)

Now I want copy this to the C:\

Now I want make a progress % for copying the dir C:\dir to C:\.

Do you get it? :$

Edited by YoseMite
Link to post
Share on other sites

ah al right...

I see that question 1 works...

Allright I explain 2nd question.

You have a folder:

C:\dir

With different files and folders on it. (50MB)

Now I want copy this to the C:\

Now I want make a progress % for copying the dir C:\dir to C:\.

Do you get it? :$

Can you use or modify this?

#include <GUIConstants.au3>

Global $Run1 = 0, $tosearch, $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $Gui


ProgressCopy("C:\MyFolderFullOfFiles", "D:\MyNewFolder")

Func ProgressCopy($current, $destination)
;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
        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]
        $Gui = 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, 0xffffff); not working with Windows XP Style if not using windows classic style
        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)
            FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, "-R")
        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, "-R")
            GUICtrlSetData($Progress1Text, $current & "\" & $file)
            ProgressCopy($current & "\" & $file, $destination)
        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($Gui)
        $Run1 = 0
    EndIf
EndFunc  ;==>ProgressCopy
Link to post
Share on other sites

you mean it doesn't overwrite a file if it already exists?

Stick ,1 at the end of the FileCopy line as below

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

You need to use one of the beta versions, but quite an old beta will work, the release AutoIT goes a bit funny!

Edited by ChrisL
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...