use warnings; use strict; $| = 1; #sets buffer to immediately flush my $mydir = 'C:\some\path'; my $destination = 'C:\some\other\path'; opendir (MYDIR, $mydir) or die "Could not opendir $mydir: $!\n"; my @files = grep { /\.ext$/} readdir MYDIR; closedir(MYDIR); for (@files) { &CopyFileProgress("$mydir\\$_","$destination\\$_",\&FileProgress); print "\n"; } sub CopyFileProgress ( ) { my $src = shift; my $dst = shift; my $callback = shift; my $num_read; my $num_wrote; my $buffer; my $total_written = 0; open (SRC, "< $src") or die "Could not open source file [$src]: $! +\n"; open (DST, "> $dst") or die "Could not open destination file [$dst +]: $!\n"; binmode SRC; binmode DST; my $filesize = (-s $src) or die "File has zero size.\n"; my $blksize = int ($filesize / 10); while (1) { $num_read = sysread(SRC, $buffer, $blksize); last if ($num_read == 0); die ("Error reading from file [$src]: $!\n") if (!defined($num +_read)); my $offset = 0; while ($num_read){ $num_wrote = syswrite(DST,$buffer,$num_read,$offset); die ("Error writing to file [$dst]: $!\n") if (!defined($n +um_wrote)); $num_read -= $num_wrote; $offset += $num_wrote; $total_written += $offset; } my $filename = basename($src); &$callback($filename, $total_written, $filesize) or die ("Copy + canceled.\n"); } } sub FileProgress { my $filename = shift; my $wrote = shift; my $size = shift; my $percent = $wrote / $size * 100; printf "%s [%-10s] %3u%% done. %5u MBs\r", $filename, '*' x int( $percent / 10 ), $percent, $wrote / 1024 / 1024; return 1; }
Very nice, thank you!!

In reply to Recoded for me.. wrapping up y'alls code by bcole23
in thread File copy progress. by zzspectrez

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.