A slightly verbose example shows %completion as it runs
#! /usr/bin/perl use strict; use File::Copy; my $tot = 0; my $SIZE_IND=7; my $smallest=2000000000; my $newLocation="/tmp"; my $some_dir = "/home/drew/temp"; opendir(DIR, $some_dir) || die "can't opendir" ; my @stats; my @dots; my $some_dir; my %dirFiles; @dots = readdir(DIR); my %fileSizes; for (my $file=0;$file <= $#dots;$file++) { if (($dots[$file] eq ".") || ($dots[$file] eq "..") || ($dots[$file] =~ /^[ ]+$/) || (-d $dots[$file])) { next; } $dirFiles{$dots[$file]} = 1;; @stats = stat $dots[$file]; $fileSizes{$dots[$file]} = $stats[$SIZE_IND]; $tot += $stats[$SIZE_IND]; if ($stats[$SIZE_IND]) { $smallest = ($smallest < $stats[$SIZE_IND])?$stats[$SIZE_IND]:$sma +llest; } } print "\n\r"; my $totPercent = 0.0; $tot.=".00"; print "\n\r"; $|=1; foreach my $file (keys(%dirFiles)) { copy($file, "/tmp/$file"); $fileSizes{$file}.=".1"; my $curPercent = ($fileSizes{$file}/$tot) * 100.0; $totPercent += $curPercent; printf STDERR "%2.2f%% complete\r", $totPercent; sleep 1; }

In reply to Re: Copying a directory and its contents wihile displaying a progress bar by Illuminatus
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.