Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Thanks for the help!!!#!/usr/bin/perl -w use strict; use File::Find; use File::Basename; use File::stat; use File::Slurp qw(read_dir); my @directories = qw( /all_files_a /all_files_b); my @files; my $min_size = 1024; # bytes => 1K my $max_size = 10485760; # bytes =>10MB for my $d (@directories) { push @files, grep { -f && -s _ >= $min_size && -s _ <= $max_size & +& /\.pdf/} read_dir( $d, prefix => 1 ); } my $limit = 5_000_000; print "Getting file sizes...\n"; $_ = -s $_ foreach (@files); #Create zip with $limit of files per zip print "Creating zips...\n"; my $zip_number = 1; my $total_size = 0; my @other_group; while(@files or @other_group) { #Find biggest file that will fit my $next_index = 0; $next_index++ while( ($next_index <= $#files) && ($total_size + + $files[$next_index] > $limit) ); #If there was a file that will fit, add it to @other_group + if($next_index <= $#files) { push @other_group, splice(@files, $next_index, 0); $total_size += $other_group[0]; } #Otherwise, zip this group, and start a new group else { # print this for testing, these files will be zipped in the $z +ip_number.zip file foreach my $testfiles (@other_group) { print "\n$testfiles - $zip_number.zip\n"; } #Clear this group info, and increment zip number @other_group = (); $total_size = 0; $zip_number++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grouping files before zipping!
by thundergnat (Deacon) on Sep 08, 2011 at 19:52 UTC | |
by Anonymous Monk on Sep 09, 2011 at 13:50 UTC | |
|
Re: Grouping files before zipping!
by ambrus (Abbot) on Sep 08, 2011 at 19:19 UTC | |
|
Re: Grouping files before zipping!
by afoken (Chancellor) on Sep 09, 2011 at 05:43 UTC | |
|
Re: Grouping files before zipping!
by Voronich (Hermit) on Sep 08, 2011 at 19:04 UTC | |
|
Re: Grouping files before zipping!
by ambrus (Abbot) on Sep 08, 2011 at 19:08 UTC |