Sign in to follow this  
Followers 0
YoseMite

Dircopy()

12 posts in this topic

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

Share this post


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)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Checkout This topic.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


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

Share this post


Link to post
Share on other sites

Thanks alot ChrisL!

That is what I need!

Share this post


Link to post
Share on other sites

I've got some overwrite problems with your script... :o

Share this post


Link to post
Share on other sites

The script overwrite not a new file...

I've changed a file from C:\dir and I copy this to D:\ but he doesn't "update" the file...

Do you get? :$

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Ah, I see it! :o

Thanks, my Enlish is not very good, but you understand me:)

Thanks anyway, 2 questions are now clear! :geek:

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