use File::Find; use File::Copy::Recursive qw(dircopy); use strict; use vars qw($dir_from $dir_to $size_all $size_remain *mycopy); $|=1; # turn off buffering is needed in this case # save the current version of copy that is used by F::C::R *mycopy = *File::Copy::Recursive::copy; # replace the copy func so we can wedge in a progressbar *File::Copy::Recursive::copy = *mycopy_func; # 1. call the original copy func # 2. calculate remaining bytes # 3. and call the show progress func sub mycopy_func { &mycopy(@_); -f $_[0] and $size_remain -= -s $_[0]; mycopy_showprogress($size_remain); } # this is called after every file is copied sub mycopy_showprogress { my ($remaining) = @_; printf "%s of %s remaining. \r",$size_remain, $size_all; sleep 1; ##### FOR DEMO ONLY, REMOVE OTHERWISE } # setup the directories to copy $dir_from = "/tmp/from"; $dir_to = "/tmp/to"; # Calculate the sum-total of the sizes of the files in the from dir $size_all = $size_remain = 0; find(sub {-f and $size_all+=-s;},$dir_from); $size_remain=$size_all; # Do it! dircopy($dir_from, $dir_to); # some visual cleanup print "\n"; __END__ #### use File::Copy::Recursive qw(dircopy); use strict; use vars qw($dir_from $dir_to *mycopy); $dir_from = "/tmp/from"; $dir_to = "/tmp/to"; sub mycopy_func { &mycopy(@_); mycopy_showprogress(@_); } sub mycopy_showprogress { my ($remaining) = @_; printf "copying %s to %s. \r",@_; sleep 1; ##### FOR DEMO ONLY, REMOVE OTHERWISE } $|=1; *mycopy = *File::Copy::Recursive::copy; *File::Copy::Recursive::copy = *mycopy_func; dircopy($dir_from, $dir_to); print "\n"; __END__