Sign in to follow this  
Followers 0

Update Progress Bar

6 posts in this topic


As I am copying a directory (DirCopy()), I would like to update my progress bar as to the status of copying. How could I do both of these simultaneously, and accurately? I was thinking of measuring the folder size, and using that to update the control, however those could only occur before or after I have copied the directory. What can I do? Thanks.

Share this post

Link to post
Share on other sites

Don't use DirCopy(), use something like THIS

Edit: Or THIS

Thanks. However, I'm confused at what to do with this. I tried the following:

_FileCopy("C:\Installed Apps\Patches\WindowsXP-KB835935-SP2-ENU.exe","C:\temp")

Func _FileCopy($fromFile,$tofile)
    Local $FOF_RESPOND_YES = 16
    $winShell = ObjCreate("shell.application")

However, nothing I do makes anything happen. Are there any other ways to do this? (I'd like to know in case I try to do something else with progress bars)

Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

Ok, never mind, I got the first thing to work. Thanks.

Actually, on second thought, (like I said earlier) are there any other ways to do it? The functions is doing weird things to my program, and I'd prefer to use DirCopy(). Is there anything else? Thanks.

Edited by mikeman118

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

You could try and do a recursive filelist to array then step through the file copy setting the progress along the way.

Here's a long winded example.

$Source = @HomeDrive & "\AutoIt Stuff\#AutoIt Projects Misc\" ; directory to copy (2.7GB)
$Destination = @HomeDrive & "\Copy Test\" ; copied to here

$FLTAR = _FileListToArrayR($Source, "", 0, 1)
ProgressOn("Copying...", "Copy Progress")
For $i = 1 To $FLTAR[0]
    If StringInStr(FileGetAttrib($FLTAR[$i]), "D") Then 
        DirCreate($Destination & StringReplace($FLTAR[$i], $Source, ""))
        FileCopy($FLTAR[$i], $Destination & StringReplace($FLTAR[$i], $Source, ""), 9)
    ProgressSet((100/$FLTAR[0]) * $i, "Copied: " & StringMid($FLTAR[$i], StringInStr($FLTAR[$i], "\", 0, -1) + 1) & _
                @CRLF & "Completed: " & Round((100/$FLTAR[0]) * $i) & "%")  

Func _FileListToArrayR($sPath, $sExFilter = "", $iFlag = 0, $iRecurse = 0, $iDepth = 0)
    Local $hSearch, $sFile, $sRxpFilter, $asFileList
    If Not $iDepth Then
        Global $sHoldFiles = ''
        If Not FileExists($sPath) Then Return SetError(1, 1, "")
        If StringRegExp($sExFilter, "[\\/<>:*?]", 0) Then Return SetError(2, 2, "")
        If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
        If Not ($iRecurse = 0 Or $iRecurse = 1) Then Return SetError(4, 4, "")
    If StringRight($sPath, 1) <> "\" Then $sPath &= "\"
    If $sExFilter = "" Then
        $sRxpFilter = "."
        $sRxpFilter = "(?i)\.(" & $sExFilter & ")"
    $hSearch = FileFindFirstFile($sPath & "*")
    If $hSearch = -1 Then Return SetError(5, 5, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($sPath & $sFile), "D") Then
            If Not $iRecurse And $iFlag = 1 Then ContinueLoop
            If $iRecurse Then
                _FileListToArrayR($sPath & $sFile, $sExFilter, $iFlag, $iRecurse, $iDepth + 1)
                If $iFlag <> 1 Then $sHoldFiles &= $sPath & $sFile & "|"
                $sHoldFiles &= $sPath & $sFile & "|"
        ElseIf StringRegExp($sFile, $sRxpFilter, 0) And $iFlag <> 2 Then
            $sHoldFiles &= $sPath & $sFile & "|"
    If Not $iDepth Then
        $asFileList = StringSplit(StringTrimRight($sHoldFiles, 1), "|")
        $sHoldFiles = ""
        Return $asFileList
EndFunc   ;==>_FileListToArrayR
There's quite a few good recursive filelist to array functions floating around the forums.


Edited by smashly
1 person likes this

Share this post

Link to post
Share on other sites

Thank you, smashly, that's exactly what I wanted!

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