Jump to content
Sign in to follow this  
Chinasmoker

About Progress

Recommended Posts

Chinasmoker

I wote a script that's base on op file, moving or copying a dir to another drive,so I used a Progress bar to show Progress of moved or copied, but Progress isn't running,below my code:

CODE
$FileSize = DirGetSize($moveR)

ProgressOn ("moved","moved")

while 1

$filemoved = Round (DirGetSize($moveD & "\"&$enddir),2)

$step = Round (($filemoved/$FileSize)*100,2)

ProgressSet( $step, $step & " percent")

WEnd

ProgressOff()


One is never too old to learn

Share this post


Link to post
Share on other sites
Danny35d

If you are using FileCopy() or FileMove() functions your script will pause until Filecopy() or Filemove() finish coping of moving files. Use AdlibEnable() to display the progress.

$FileSize = DirGetSize($moveR)
ProgressOn ("moved","moved")
AdlibEnable("_Progress")
FileMove("C:\foo.au3", "D:\mydir\bak.au3")
ProgressOff()
AdlibDisable()

Func _Progress()
   $filemoved = Round (DirGetSize($moveD & "\"&$enddir),2)
   $step = Round (($filemoved/$FileSize)*100,2)
   ProgressSet( $step, $step & " percent")
EndFunc

Edited by Danny35d

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

Share this post


Link to post
Share on other sites
Chinasmoker

If you are using FileCopy() or FileMove() functions your script will pause until Filecopy() or Filemove() finish coping of moving files. Use AdlibEnable() to display the progress.

$FileSize = DirGetSize($moveR)
ProgressOn ("moved","moved")
AdlibEnable("_Progress")
FileMove("C:\foo.au3", "D:\mydir\bak.au3")
ProgressOff()
AdlibDisable()

Func _Progress()
   $filemoved = Round (DirGetSize($moveD & "\"&$enddir),2)
   $step = Round (($filemoved/$FileSize)*100,2)
   ProgressSet( $step, $step & " percent")
EndFunc
does it need loop ? _progress.

One is never too old to learn

Share this post


Link to post
Share on other sites
Danny35d

No it doesn't need a while loop. Once your script do AdlibEnable() it will call _Progress() function every 250 ms until it finish moving files and call AdlibDisable()


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

Share this post


Link to post
Share on other sites
Chinasmoker

No it doesn't need a while loop. Once your script do AdlibEnable() it will call _Progress() function every 250 ms until it finish moving files and call AdlibDisable()

I ve patched it ,but the progress bar stayed 0 percent,then auto-closed that window,code:

CODE
Func move()

$moveR = GUICtrlRead($Input1)

$moveD = GUICtrlRead($Input2)

$spdir = StringSplit($moveR, "\")

$enddir = $spdir[$spdir[0]]

;msgbox(0,"",$spdir[$spdir[0]])

$FileSize = DirGetSize($moveR)/1048576

ProgressOn ("移动进度","已移动")

AdlibEnable("_Progress")

DirCopy ($moveR,$moveD & "\"&$enddir)

ProgressOff()

AdlibDisable()

EndFunc

Func _Progress()

Dim $filemoved,$moveD,$enddir,$FileSize

$filemoved = Round (DirGetSize($moveD & "\"&$enddir)/1048576,2)

$step = Round (($filemoved/$FileSize)*100,2)

ProgressSet( $step)

EndFunc

Thank you


One is never too old to learn

Share this post


Link to post
Share on other sites
Danny35d

You have this line (Dim $filemoved,$moveD,$enddir,$FileSize) inside _Progress() function so every time AdlibEnable("_Progress") call the function reset the value of $filemoved,$moveD,$enddir,$FileSize. Make the following variables global $moveD,$enddir,$FileSize

Try it:

Global $moveD, $enddir, $FileSize

Func move()
    $moveR = GUICtrlRead($Input1)

    $moveD = GUICtrlRead($Input2)

    $spdir = StringSplit($moveR, "\")
    $enddir = $spdir[$spdir[0]]
    ;msgbox(0,"",$spdir[$spdir[0]])
    $FileSize = DirGetSize($moveR) / 1048576



    ProgressOn("????", "???")
    AdlibEnable("_Progress")
    DirCopy($moveR, $moveD & "\" & $enddir)
    ProgressOff()
    AdlibDisable()

EndFunc   ;==>move

Func _Progress()
    Dim $filemoved

    $filemoved = Round(DirGetSize($moveD & "\" & $enddir) / 1048576, 2)
    $step = Round(($filemoved / $FileSize) * 100, 2)
    ProgressSet($step)

EndFunc   ;==>_Progress

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  

×