OK, here is my proposal: my script makes a hierarchy of directories, the depth depending on how many files fall in the given namespace. It ensures that there are not more than a given number of files in any dir. It doesn't guarantee, however, that some of the dirs contain fewer files. But it's fairly simple and I suggest you give it a go and let me know how it worked for you...
#!/usr/bin/perl -w
use strict;
my $maxFiles = 100; #max no of files per directory
my $dir = shift;
chdir $dir or die "Cant change to directory $dir: $!\n";
foreach my $i (0..9) {
partitionRecursive ($i, '.');
}
sub partitionRecursive {
my ($prefix, $path) = @_;
my @files = glob ("$prefix*");
return unless @files;
mkdir "$path/_$prefix" or die "Cant make dir $path/_$prefix: $!\n"
+;
if (@files < $maxFiles) {
#if there are less than maxFiles, move them all to the new dir
system ("mv $prefix* $path/_$prefix") == 0 or die "Cant move f
+iles to $prefix: $!\n";
}
else {
#otherwise, move those with one more character than the prefix
+ to the new dir
#can be omitted if all filenames are equal in length
system ("mv $prefix? $path/_$prefix") == 0 or die "Cant move f
+iles to $prefix: $!\n";
}
foreach my $nextDigit (0..9) {
partitionRecursive ("$prefix$nextDigit", "$path/_$prefix");
}
}
pike
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.