Jump to content

Update Progress Bar


Recommended Posts

Hi,

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.

Link to comment
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
    Local $FOF_SIMPLEPROGRESS = 256
    $winShell = ObjCreate("shell.application")
    $winShell.namespace($tofile).CopyHere($fromFile,$FOF_RESPOND_YES)
EndFunc

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)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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, ""))
    Else    
        FileCopy($FLTAR[$i], $Destination & StringReplace($FLTAR[$i], $Source, ""), 9)
    EndIf
    ProgressSet((100/$FLTAR[0]) * $i, "Copied: " & StringMid($FLTAR[$i], StringInStr($FLTAR[$i], "\", 0, -1) + 1) & _
                @CRLF & "Completed: " & Round((100/$FLTAR[0]) * $i) & "%")  
Next    


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, "")
    EndIf
    If StringRight($sPath, 1) <> "\" Then $sPath &= "\"
    If $sExFilter = "" Then
        $sRxpFilter = "."
    Else
        $sRxpFilter = "(?i)\.(" & $sExFilter & ")"
    EndIf
    $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 & "|"
            Else
                $sHoldFiles &= $sPath & $sFile & "|"
            EndIf
        ElseIf StringRegExp($sFile, $sRxpFilter, 0) And $iFlag <> 2 Then
            $sHoldFiles &= $sPath & $sFile & "|"
        EndIf
    WEnd
    FileClose($hSearch)
    If Not $iDepth Then
        $asFileList = StringSplit(StringTrimRight($sHoldFiles, 1), "|")
        $sHoldFiles = ""
        Return $asFileList
    EndIf
EndFunc   ;==>_FileListToArrayR
There's quite a few good recursive filelist to array functions floating around the forums.

Cheers

Edited by smashly
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...