while (system($cmd)) {} #### #!/usr/bin/perl use warnings; use strict; use warnings; use Tk; use Tk::ProgressBar; use IPC::Open3; use File::Find; my $count = 0; my $tot = 0; my $dir_from = '/home/zentara/1down/goodstuff'; my $dir_to = '/home/zentara/1'; finddepth sub { return if $_ eq "." or $_ eq ".."; # print "$File::Find::name\n"; $tot++; }, $dir_from; print "tot $tot\n"; my $mw = new MainWindow( -title => 'Progress Bar Demo' ); my $top = $mw->Frame()->pack( -expand => 1, -fill => 'both' ); my $percent_done = 0; my $pb = $top->ProgressBar( -width => 20, -height => 200, -from => 0, -to => 100, -blocks => 10, -colors => [ 0, 'green', 50, 'yellow', 80, 'red' ], -variable => \$percent_done )->pack(); $mw->after( 100 => \©_loop ); MainLoop; sub copy_loop { #now use IPC to read output of $cmd and #update progressbar for each file... #not accurate, but fast but overwhelms progressbar widget my $pid = open3( 0, \*READ, 0, "cp -va $dir_from $dir_to" ); $mw->fileevent( \*READ, 'readable', \&update_pbar ); } sub update_pbar { $_ = ; $count++; $percent_done = $count / $tot * 100; $pb->update; } #### #!/usr/bin/perl use warnings; use strict; use warnings; use Tk; use Tk::ProgressBar; use File::Find; my $count = 0; my $tot = 0; my $orig = '/home/zentara/1down/goodstuff'; my $new = '/home/zentara/1'; finddepth sub { return if $_ eq "." or $_ eq ".."; # print "$File::Find::name\n"; $tot++; }, $orig; print "tot $tot\n"; my $mw = new MainWindow( -title => 'Progress Bar Demo' ); my $top = $mw->Frame()->pack( -expand => 1, -fill => 'both' ); my $percent_done = 0; my $pb = $top->ProgressBar( -width => 20, -height => 200, -from => 0, -to => 100, -blocks => 10, -colors => [ 0, 'green', 50, 'yellow', 80, 'red' ], -variable => \$percent_done )->pack(); $mw->after( 100 => \©_loop ); MainLoop; sub copy_loop { ####################################################### # original by broquiant of perlmonks use File::Basename 'basename'; use File::Find::Rule 'find'; use File::Path 'mkpath'; use File::Copy 'copy'; use File::Spec::Functions qw/ splitdir catdir splitpath catfile /; my $iter = find start => $orig; while ( my $ent = $iter->match ) { if ( -d $ent ) { my $mode = ( stat $ent )[ 2 ]; my @src = splitdir $ent; my $dest = catdir $new => @src; mkpath $dest => 0, $mode or warn " Couldn't create '$ent': $!"; } else { my @src = splitpath $ent; my $dest = catfile $new => @src; copy $ent => $dest or warn " Couldn't copy '$ent': $!"; } $count++; $percent_done = $count / $tot * 100; $pb->update; } ################################################### }