You need to be more specific in what you mean "copy a directory from one location to another". Is this a local operation? Or over the network? A local operation can be so fast, that the progress indicator will not have time to work. I usually use Midnight Commander for my local moves, and it shows a nice curses progress bar for huge files.

You would make your life alot easier if you can tar or zip up your directory, and just move the single file.

Since you mention File::Find, I will assume a local move. If you want to do this on a local filesystem, you would need to open the source dir and target dir, then manually open and sysread each file in small chunks, then as you write them to the target dir, make your 'progress dot'. You could do a total byte count before starting the copy, so you could get a byte percentage. The problem with doing this, is it will slow down all your file transfers..... so why bother?

In general: when you want to show progress, you need to intercept the callback that does the copying. Like this with LWP. ( Also see Track file upload progress )

#!/usr/bin/perl -w use strict; use LWP::UserAgent; # don't buffer the prints to make the status update $| = 1; my $ua = LWP::UserAgent->new(); my $received_size = 0; my $url = 'http://www.cpan.org/authors/id/J/JG/JGOFF/parrot-0_0_7.tgz' +; print "Fetching $url\n"; my $request_time = time; my $last_update = 0; my $response = $ua->get($url, ':content_cb' => \&callback, ':read_size_hint' => 8192, ); print "\n"; sub callback { my ($data, $response, $protocol) = @_; my $total_size = $response->header('Content-Length') || 0; $received_size += length $data; # write the $data to a filehandle or whatever should happen # with it here. Otherwise the data isn't saved my $time_now = time; # this to make the status only update once per second. return unless $time_now > $last_update or $received_size == $total_s +ize; $last_update = $time_now; print "\rReceived $received_size bytes"; printf " (%i%%)", (100/$total_size)*$received_size if $total_size; printf " %6.1f/bps", $received_size/(($time_now-$request_time)||1) if $received_size; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: Copying a directory and its contents wihile displaying a progress bar by zentara
in thread Copying a directory and its contents wihile displaying a progress bar by bittis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.