Saturday, January 2, 2016
too many files in directory need to split into subdirectories with 100 files
#!/usr/bin/perl -w
use strict;
use File::Copy;
my $fn;
my @total= (1 .. 100);
my $dir = shift;
opendir (my $dh , $dir);
my @files = grep { $_ ne '.' && $_ ne '..' } readdir $dh;
my @letters = ("a".."z") ;
MYLOOPS:
foreach my $let1 ( @letters ) {
foreach my $let2 (@letters) {
mkdir "$dir$let1$let2";
for my $count (@total) {
$fn = pop @files;
if ( $fn ) {
move ("$dir/$fn", "$dir$let1$let2/$fn");
} else {
last MYLOOPS;
}
} }}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment