Baratski has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Xcopy in a batch file to backup files to my CDRW.

When my cdrw drive is idle for a long period of time, xcopy fails to copy the first line in the batch file. Only after my burner is completely "on-line" does this not happen.

So I've decided to use perl to "wake up" my burner prior to backing up, so that it's ready.

I'm using File::Find to recurse the disk in my cdrw drive prior to backing up. This is where my problem comes in.

I can't seem to get the progressbar and sub routine used with File::Find to match up. My bar fnishes before the whole process does.

I don't want a progressbar thats 1000 pixels wide?
I hope I've been clear with my question.

Thanks.

Replies are listed 'Best First'.
(jeffa) Re: Progressing a ProgressBar...
by jeffa (Bishop) on Jul 29, 2003 at 20:40 UTC
Re: Progressing a ProgressBar...
by Cine (Friar) on Jul 29, 2003 at 20:26 UTC
    Not really :)
    What do you want your progressbar to show? The progress you are doing in finding files on your cd? In that case, its a bit hard, because how do you know how many files there are before finding them?
    So you must be looking for the progress of the copy operation. So first you have to know the total number of bytes to copy and then you have to keep an eye on how much you have actually copied.
    Does that help you? Else see this code: File copy progress.

    T I M T O W T D I
      .... $prog = $progframe-> ProgressBar( -from=> 0, -to=> 200, -blocks=> 1, -gap=> 0, -variable=> \$count, )->pack( -fill=> 'x', -expand=> 1, ); finddepth(\&wakecdrw, "$source"); MainLoop; sub wakecdrw { # Just looking for directories. # I'm not doing anything with $_ if(-d "$_") { # I'm also updating an Entry widget here. $path = "$File::Find::name"; $displaypath->update(); # ProgressBar variable incrimented here. $count++; } }

      That's it.

      Obviously if there are more than 200 directories, I run into a problem.

      Is there a way to update the progressbar to reflect the whole process of recursing my CDRW drive?

        You can solve this if you use use a progressbar that works like your browser progress bar. It displays how many searched directories out of the total number of directories seen (in the browser it displays number of link/pics gotten out of how many links there have been seen on the current page).
        But for that to work, you do need to calculate your own progress, but it should be as simple as $prog->value( 100 * $numdirssearched / $numdirsseen );
        And then you have to use a bread-first search, which is NOT what finddepth does...

        T I M T O W T D I
Re: Progressing a ProgressBar...
by waswas-fng (Curate) on Jul 29, 2003 at 21:23 UTC
    If you are just finding on the CDRW to wake it, what would be wrong with :
    while (1) { # mabe a notice that your app is waiting for CDRW device to wake up he +re... open (TESTCDRW, ">$path_to_cdrw/touchtest.txt") and last; sleep 1; } close (TESTCDRW); do your stuff here...
    instead of finding the cdrw data? This should loop until the cdrw is able to be written to.

    -Waswas
Re: Progressing a ProgressBar...
by blue_cowdawg (Monsignor) on Jul 29, 2003 at 20:12 UTC

        I can't seem to get the progressbar and sub routine used with File::Find to match up. My bar fnishes before the whole process does. I don't want a progressbar thats 1000 pixels wide? I hope I've been clear with my question.

    Code sample please?


    Peter @ Berghold . Net

    Sieze the cow! Bite the day!

    Test the code? We don't need to test no stinkin' code! All code posted here is as is where is unless otherwise stated.

    Brewer of Belgian style Ales