Dear Monks,

I need some better options for the thing i tried.

I am doing a job in which i will get a folder path which inturn contains a many directories which has many files in it.

What i want is, i have to find the size of each directories in the given directory and i have to make a new directory and push it in the new directory with some conditions.

The condition is, suppose if a directory size is 20 MB then i have to push it into new directory like wise other directories until the sum of the size between 179 and 195 MB. (the directory sizes are not constant, it may vary)

Suppose if the sum of the size not matches the above condition (between 179 and 195), then we can push the next directory similarly, till the above condition satisfies.

Likewise i want to split those directories and place it in the new folders.

What i have tried is working correctly, sometimes it works for different size of directories, but sometimes the loop is not ending as the size is always varying.

Here i am posting the loop section alone, is there any other better options to do it.

Sorry for posting a ugly code, because you may know what i have tried.

opendir (FUL, "fullset") or die("fullset does not exists\n"); #open th +e fullset directory my @full= grep /000/, readdir(FUL); #reading fullset folder my @final =(); my @tfin =(); my $total1=''; my $whole=''; my $size=''; my $total=''; my $megs=''; my $s; do { my $TotalSize=''; $f1 = shift @full; my @t = "$cd\/fullset\/$f1"; sub find(&@) { &File::Find::find } *name = *File::Find::name; find { $size=-s($name); $TotalSize+=$size; } @t; my $megs = sprintf "%5.2f",($TotalSize/(1024*1024)); $total=$total + $megs; if($total <= 179) { push (@tfin, $f1); } if (($total <= 195) &&($total > 179)) { push (@tfin, $f1); push (@final, @tfin); print "$total\t@final\n"; $hash{$mfname.$mfold++}= [@final]; @tfin =(); @final =(); $total=0; $megs=0; } if ($total > 195) { push (@full, $f1); $total = $total - $megs; } }until (@full<= 4); $hash{$mfname.$mfold++}= [@tfin];#for the last split @sparr = splice(@full, 2, 2);#split last four into two $hash{$mfname.$mfold++}= [@full];# $hash{$mfname.$mfold++}= [@sparr];# #print "@{$hash{$_}}\n" for (keys %hash);

Thanks in advance,

Prasad

Updated Steve_p - added readmore tags


In reply to split directories with sizes by prasadbabu

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.