I have an array

@tmp qw/1.zip 2.zip 3.zip 4.zip 5.zip 6.zip 7.zip 8.zip 9.zip/;

1. I need to search a location to find each zip file and size of each zip file.

2. Copy the files over to a new location.

3. If the directory reaches 4gb's, make a new directory and start to populate it, if that reaches a limit make another, and so on.

E.G.

my @tmp = qw/1.zip 2.zip 3.zip 4.zip 5.zip 6.zip 7.zip 8.zip 9.zip/; Directory location: Source----- Destination /home/svr/1.0 /home/des/Disk1/Linux /CD_RH_1 /CD_RH_2 /CD_RH_3 /CD_RH_4 foreach (@tmp) to find /home/svr/1.0/CD_RH_2/1.zip => 2 gb [copy to destination] /home/svr/1.0/CD_RH_1/2.zip => 1 gb [copy to destination] --------------So only 1.zip and 2.zip can fit in /home/des/Disk1/Linux Adding 3.zip would go over 4 gb --------------mkdir /home/des/Disk2/Linux /home/svr/1.0/CD_RH_3/3.zip => 2gb [copy to destination] --------------only 3.zip can ! fit in /home/des/Disk2/Linux Adding 4.zip would go over 4 gb --------------mkdir /home/des/Disk3/Linux /home/svr/1.0/CD_RH_4/4.zip => 2.5gb [copy to destination] /home/svr/1.0/CD_RH_2/5.zip => .5mb [copy to destination] /home/svr/1.0/CD_RH_1/6.zip => .25gb [copy to destination] /home/svr/1.0/CD_RH_3/7.zip => 112.5mb [copy to destination] /home/svr/1.0/CD_RH_4/8.zip => 22.5mb [copy to destination] /home/svr/1.0/CD_RH_4/9.zip => 122.5kb [copy to destination] --------------copy 4.zip 5.zip 6.zip 7.zip 8.zip 9.zip to /home/des/Di +sk3/Linux

Code tags added by GrandFather and much editing of misguided HTML

Code I have This is the code I have.

I now need to use my @tmp = qw/1.zip 2.zip 3.zip 4.zip 5.zip 6.zip 7.zip 8.zip 9.zip/; with this to find each element in /home/svr/1.0 copy to /home/des/Disk$dest/Linux and if /home/des/Disk$dest/Linux reaches 4gb make another and start coping. The copy has to be in the order of the array.

opendir(DIR,"/home/svr/1.0"); @dir_list = grep(/^RH_CD\d+$/,readdir(DIR)); closedir(DIR); foreach $dir (@dir_list) { opendir(DIR,"/home/svr/1.0/$dir"); @file_list = grep(!/^\.\.?$/,readdir(DIR)); closedir(DIR); foreach $file (@file_list) { $filename = "/home/svr/1.0/$dir/$file"; $base{"$dir/$file"} = $file; if (-f $filename) { $filesize{"$dir/$file"} = -s $filename; }elsif (-d $filename) { chomp($filesize{"$dir/$file"} = qx(du -sk $_)); $filesize{"$dir/$file"} *= 1024; } } } $limit = 4*1024*1024*1024; $dest = 1; chomp($dest_size = qx(du -sk "/home/des/Disk1$dest/Linux")); $dest_size *= 1024; while (%filesize) { $got_onfiltered= 0; foreach (sort {$filesize{$a} <=> $filesize{$b}} keys %filesize) { last if $dest_size + $filesize{$_} > $limit; system("cp -Rp /home/svr/1.0/$_ /home/des/Disk$dest/Linux/$base{$ +_}"); $dest_size = $dest_size + $filesize{$_}; delete $filesize{$_}; $got_onfiltered= 1; } if (!$got_one) { if ($dest_size == 0){ print "ERROR: all remaining files too big:\n"; foreach (keys %filesize) { print "$_: $filesize{$_}\n"; } die; }else{ $dest++ mkdir ("/home/des/Disk$dest/Linux) $dest_size = 0; } } }

20060317 Corion: Un-htmlified addendum


In reply to Using an array, how do I search one directory area and copy to another area by ckaspar

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.