Hentie Posted June 12, 2005 Share Posted June 12, 2005 (edited) This is driving me nuts... I've searched the forums for a solution to get a progressbar while copying a file but the only real answer was that you need to run a secondary script with a progressbar. That does not suit me so I tried to BS the system in a different way. My script seemed to work fine in the beginning but after a while it just stopped working. It will get to 1% and not continue with the loop...? What I don't understand is that it was working fine and without anything changing (that I know of) it just stopped working. Here's the script, I hope somebody can help me... Func FileAction($Action, $SourceFile, $DestinationFile) $i = FileGetSize($SourceFile) If $i = 0 Then ;File not found or file does not exist MsgBox(48, @ScriptName, 'Source File Not Found!') Return 0 ;error Else $i = $i / 1024 $i = $i / 1024 $estimate = Round($i) + 1 ; $estimate is now a rough estimate of the filesize ; string count $i: if $i = 4 (2343 MB) then divide by string count 3.1 (3characters.last character) , example... 2343 / 234.3 will give you ten ; if stringcount = 3 example 596 then DIV 59.6, if stringcount 2 example 15 then div by 1.5 $c = StringLen($estimate) $c_left = StringLeft($estimate, ($c - 1)) $c_right = StringRight($estimate, 1) $div_nr = $c_left & "." & $c_right ;The Nr to divide the kilobytes with to get 10. $k = 100 / $div_nr $t = $div_nr / $k ;Copy or Move the File... Depending on $Action $procid = Run(@ComSpec & ' /c ' & $Action & ' "' & $SourceFile & '" "' & $DestinationFile & '"', '', @SW_HIDE) $t = $t * 1000 $t = Round($t, -1) ProgressOn(@ScriptName, "File " & StringLower($Action) & " in progress...", "0 percent") For $z = 1 To 100 Sleep($t) If ProcessExists($procid) Then ProgressSet($z, $z & " percent") Else ;File has finished copying and we need to rush the progressbar For $n = $z To 100 Sleep($t) ProgressSet($n, $n & " percent") If $n = 100 Then $z = 100; ProgressSet($z, $z & " percent - Done!") Sleep(1000) If not (ProcessExists($procid)) Then ProgressOff() EndIf EndIf Next EndIf If ($z = 100) And (ProcessExists($procid)) Then ;Progressbar is at 100% and the file is still copying. ProcessWaitClose($procid) ProgressSet($z, $z & " percent - Done!") Sleep(1000) EndIf ProgressOff() Return 1 ;success Next EndIf EndFunc ;==>FileActionHfileCopy2.au3 Edited November 7, 2005 by Hentie Link to comment Share on other sites More sharing options...
MHz Posted June 12, 2005 Share Posted June 12, 2005 (edited) This is driving me nuts... I've searched the forums for a solution to get a progressbar while copying a file but the only real answer was that you need to run a secondary script with a progressbar. That does not suit me so I tried to BS the system in a different way.<{POST_SNAPBACK}>Need to run a second script? That should not be required.Just a brief search in Scripts and scraps, catches this nice UDF, here.Or you can try and reinvent the UDF yourself? Edited June 12, 2005 by MHz Link to comment Share on other sites More sharing options...
Hentie Posted June 12, 2005 Author Share Posted June 12, 2005 (edited) Need to run a second script? That should not be required.Just a brief search in Scripts and scraps, catches this nice UDF, here.Or you can try and reinvent the UDF yourself? <{POST_SNAPBACK}>Thanks for that but I've already looked at the script. While it's great for copying multiple smaller files it does seem to have a similar problem when copying one file, the progressbar stays on 0. Edited June 12, 2005 by Hentie Link to comment Share on other sites More sharing options...
PerryRaptor Posted June 12, 2005 Share Posted June 12, 2005 ProgressSet() updates the ProgressBar everytime a loop event occurs. You would have to pause the copying of a single file; adjust ProgressSet() then loop. I do not know how to pause the filecopy() event. Link to comment Share on other sites More sharing options...
Hentie Posted June 12, 2005 Author Share Posted June 12, 2005 (edited) Well, I'm not using filecopy() for that very reason. I'm using: $procid = Run(@ComSpec & ' /c ' & $Action & ' "' & $SourceFile & '" "' & $DestinationFile & '"', '', @SW_HIDE) for example... ($procid = Run(@ComSpec & ' /c C:\Temp\1.dat C:\Temp2.dat' , '', @SW_HIDE) ...then I start looping using a pause time that I derived from the file size. Edited June 12, 2005 by Hentie Link to comment Share on other sites More sharing options...
PerryRaptor Posted June 12, 2005 Share Posted June 12, 2005 I assumed $Action = FileCopy()...I don't know of a way to pause the line: $procid = Run(@ComSpec & ' /c ' & $Action & ' "' & $SourceFile & '" "' & $DestinationFile & '"', '', @SW_HIDE) The Run() command does not have a status report nor a pause feature. This command pauses script execution until the run event is completed. I'm thinking your only solution will be to call the Windows Copy Command to get a progressbar. Link to comment Share on other sites More sharing options...
Hentie Posted June 12, 2005 Author Share Posted June 12, 2005 Well... the command 'Run(@ComSpec & '/s COPY Sourcefile DestFile)' starts the copy process and then I handle the rest in a loop. This does work... well, it did work... I thank you for trying to help but I need someone to actually look at the code and see if he/she can see anything obvious wrong. The $Action variable can be anything that @Comspec allows with a source file and destination file. I use either $Action = Move or $Action = Copy. At this time I am inclined to think that I might have encountered a bug with AutoIT v3, either with it's process handling or with looping. Link to comment Share on other sites More sharing options...
t0ddie Posted June 12, 2005 Share Posted June 12, 2005 (edited) dont some browsers (i think) keep track of some large files while you are downloading? i was cut off in the middle of an hour download one time, and when i started it back up, it didnt start from the beginning, it started where it left off. maybe you could measure it in a way, using InetGet("abort") then checking the size of the file, then starting it again, in a loop. of course that would only be for online files. Edited June 12, 2005 by t0ddie Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you. Link to comment Share on other sites More sharing options...
Hentie Posted June 13, 2005 Author Share Posted June 13, 2005 I don't see how that can work... Link to comment Share on other sites More sharing options...
blitzkrg Posted June 14, 2005 Share Posted June 14, 2005 (edited) as part of a program i wrote (in autoIT 2) i needed a progress bar when downloading a file, i created "tools.exe" and call it when i need some things i couldnt do in autoIT2 a progress bar was one of them. now my file is the same size, so you'll need to come up with a way to change that part of it.. but this works for me, when copying a single file. Case $var = "progress" ProgressOn("Downloading Database", "Please wait...", "0 % complete", -1, -1, 16) Do $size = FileGetSize($Cmdline[2]) $size2 = $size / 1024 $i = Round($size2) $x = 100 * $i / 800 $y = Round($x) Sleep(500) ProgressSet($y, $y & " % complete") Until $y > 98 ProgressSet(100, "Done", "Completed") ProgressOff() Exit btw i'm an autoIT 3 n00b.. sorry if my code sux Edited June 14, 2005 by blitzkrg Link to comment Share on other sites More sharing options...
Hentie Posted June 16, 2005 Author Share Posted June 16, 2005 There does not seem to be anything wrong with the code. Although I will need to have a look at how it works before I understand completely how the $Cmdline[2] parameter(array) fits in. I don't particularely like calling another script to perform a function that should be seemless but since we are forced to by limits I'll give it a try. Seems like nobody else has a solution either. Thanks for your input. Link to comment Share on other sites More sharing options...
blitzkrg Posted June 17, 2005 Share Posted June 17, 2005 well i had written an enormous script in autoIT 2 and wasnt about to convert it or re-write it.. but i was using a few 3rd party utilities to perform some functions i couldnt do in v.2 so i finally gave in and started to learn v3 (glad i did) so i was able to write "tools.exe" which is basically a bunch of fucntions that i need.. so i can get rid of all my 3rd party tools.. so i invoke it by running the standard commands then \tools.exe <param1> <param2> (and if needed 3 and 4 param1 is the function i need for this instance it's a progress bar and you can see the 1st line says Case $var = "progress" that's the start of my progress bar function <param2> (which is really CmdLine[2]) is the name of the file that i'm running the progress bar on so from autoIT 2 it's command ......\tools.exe progress %server%\\filename.ext then while autoIT 2 is copying the file over from the server, the progress bar starts looking at the file size and it continually looks at the size.. getting the percent of the total size (which i know ahead of time) to be 800k now you could write code to get this automatically but i didnt need to worry about that since in my case the file stayed the same all the time. other functions are called the same way command ......\tools.exe <whatever function i need here> <file name of the file i'm running the function on> soooo thats how all that works.. i'm not suggesting you do any of that.. i myself also prefer everything in one script.. but it wasnt an option due to the autoIT 2 script. so maybe you can take my code and somehow work it into your one script.. it does work for me with no problems. Link to comment Share on other sites More sharing options...
jamesband Posted June 17, 2005 Share Posted June 17, 2005 It seems to me that you are looking at the Progress Percent from the wrong angle. You are getting the size of the source file. Just monitor the size of the destination file inside a while loop and calculate the percent complete. For example:$size_source = FileGetSize($source) $cmdproc =;launch the copy cmd here While ProcessExists( $cmdproc ) Sleep( 500 ) $cmdprog = Round( FileGetSize( $destination ) / $size_source * 100, 0 ) ProgressSet( $cmdprogress, $cmdprog & " percent complete", $source ) WendNow, when you copy a file with something like the above it works fine. If you are copying a Dir you would need add extra code to determine if the source is a file or Dir and deal with getting the size accordingly.Hope this helps.This is driving me nuts... I've searched the forums for a solution to get a progressbar while copying a file but the only real answer was that you need to run a secondary script with a progressbar. That does not suit me so I tried to BS the system in a different way. My script seemed to work fine in the beginning but after a while it just stopped working. It will get to 1% and not continue with the loop...? What I don't understand is that it was working fine and without anything changing (that I know of) it just stopped working. Here's the script, I hope somebody can help me...Func FileAction($Action, $SourceFile, $DestinationFile) $i = FileGetSize($SourceFile) If $i = 0 Then ;File not found or file does not exist MsgBox(48, @ScriptName, 'Source File Not Found!') Return 0 ;error Else  $i = $i / 1024 $i = $i / 1024 $estimate = Round($i) + 1 ; $estimate is now a rough estimate of the filesize ; string count $i: if $i = 4 (2343 MB) then divide by string count 3.1 (3characters.last character) , example... 2343 / 234.3 will give you ten ; if stringcount = 3 example 596 then DIV 59.6, if stringcount 2 example 15 then div by 1.5 $c = StringLen($estimate) $c_left = StringLeft($estimate, ($c - 1)) $c_right = StringRight($estimate, 1) $div_nr = $c_left & "." & $c_right ;The Nr to divide the kilobytes with to get 10. $k = 100 / $div_nr $t = $div_nr / $k  ;Copy or Move the File... Depending on $Action $procid = Run(@ComSpec & ' /c ' & $Action & ' "' & $SourceFile & '" "' & $DestinationFile & '"', '', @SW_HIDE) $t = $t * 1000 $t = Round($t, -1) ProgressOn(@ScriptName, "File " & StringLower($Action) & " in progress...", "0 percent") For $z = 1 To 100 Sleep($t) If ProcessExists($procid) Then  ProgressSet($z, $z & " percent") Else ;File has finished copying and we need to rush the progressbar    For $n = $z To 100  Sleep($t)  ProgressSet($n, $n & " percent")  If $n = 100 Then   $z = 100;   ProgressSet($z, $z & " percent - Done!")   Sleep(1000)   If not (ProcessExists($procid)) Then   ProgressOff()   EndIf  EndIf    Next EndIf   If ($z = 100) And (ProcessExists($procid)) Then ;Progressbar is at 100% and the file is still copying.  ProcessWaitClose($procid)  ProgressSet($z, $z & " percent - Done!")  Sleep(1000) EndIf   ProgressOff() Return 1 ;success   Next EndIf EndFunc ;==>FileAction<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
blitzkrg Posted June 17, 2005 Share Posted June 17, 2005 (edited) I miss typed my reply.. to him.. i'm not actually getting from the server.. you are right.. it should have read command....\tools.exe progress <destination file> what i'm specifically doing is compressing a file on the fly and transfering it over to the temp drive.. this is my actual command Runwait, %COMSPEC% /c %tempdir%\\tools.exe progress %tempdir%\\cab2.,,hide were cab2. is the file name of the compressed file (when it's done transfering it becomes database.dat) but while it's compressing and transfering makecab.exe calles it "cab2." so i run my progress bar against that file..when it hit's 98% i call it quits with the progress bar and a second or 2 later it's done and renamed to it proper file name. the autoit 2 script then moves on with it's next task. Edited June 17, 2005 by blitzkrg Link to comment Share on other sites More sharing options...
Hentie Posted November 4, 2005 Author Share Posted November 4, 2005 Hi there I finally looked at this again and found the answer. It was sooooo simple. I had a return statement in the Progress loop, hence the progressbar will go through the first loop then return a value and stop. Cheers! java script:emoticon('', 'smid_20') HFileCopy.au3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now