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

You already mentioned in the CB that you're trying to use File::Find for that solution, and I really recommend it. The below skeleton should get you closer to your solution:

use strict; use File::Find; my $limit = 4 * 1024 * 1024 * 1024; my @source_directories = qw( ); my @files; File::Find::find( sub { push @files, $File::Find::name }, @source_dire +ctories ); my $total; my $basename = "part-"; my $count = 1; my $dirname = $basename . $count; for my $file (@files) { my $size = -s $file; if ($total + $size > $limit) { $total = 0; $count++; $dirname = $basename . $count; print "# 4GB Limit reached, starting new volume $dirname"; }; print "$file => $dirname/$file\n"; };
  • Comment on Re: Using an array, how do I search one directory area and copy to another area
  • Download Code

Replies are listed 'Best First'.
Re^2: Using an array, how do I search one directory area and copy to another area
by Tanktalus (Canon) on Mar 19, 2006 at 17:53 UTC

    Please note that simply looking at a file's size does not do the same thing as du. The du command will tell you the amount of disk space that each file is using by rounding up to the current sector size. This discrepency was the whole purpose of cog's Filesys::DiskUsage 0.04 version - to allow you to better approximate what the du command does. Note that you have to tell Filesys::DiskUsage what sector size to use, which is moderately (but not completely) unfortunate.

    This is completely fortunate, however, in the OP's scenario. I'm betting that the 4GB boundary is for DVDs. And DVDs will not have the same sector size as their ext3 or jfs or ntfs or whatever filesystem. So what du thinks is the total space and what it will be on the DVD may not match. It may be close enough, but maybe not.

    As I said above, I did exactly the same thing for CDs. And the sector size on CDs is 1K. Which doesn't often match the sector size on hard disks. So I use Filesys::DiskUsage and pass in a sector-size of 1024, and I know what the disk usage will be on my target media. In my case, the difference will be dozens of MB between what du reports on the hard disk and what it would report on CDs, and that difference could significantly alter the layout of the CDs, possibly even reducing the number of CDs that I need by one - multiplied over the cost of manufacturing, it can save some real dollars, not only likely saving the cost of developing that patch and using it, but also reducing the weight of the box the CDs are in, and producing less ill will from customers who don't like how many CDs we already have in those boxes - that's worth real money, too.