#!/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; }