in reply to Finding and sorting files in massive file directory
This example deals with directory entries at the most efficient and lowest level. In this case, it just moves all files starting with "b" into the subdirectory b/.#!/usr/bin/perl use warnings; use strict; opendir my $dir, '.' or die "opendir .: $!\n"; my $file; my $count = 0; while (defined($file = readdir($dir))) { # give yourself some progression feedback $count++; print "file $count ...\n" unless $count % 1000; # skip all files not begining with b next unless $file =~ /^b/; # if you've created directories, may need to skip them; # this will slow things down, so don't do so unless necessary next unless -f $file; # do something with the file rename $file, "b/$file" or die "rename $file b/$file: $!\n"; }
Obviously it needs adapting to your particular needs. For example, the rename could become
system "gzip", $file;
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding and sorting files in massive file directory
by CColin (Scribe) on Jan 20, 2013 at 21:28 UTC | |
by dave_the_m (Monsignor) on Jan 20, 2013 at 22:41 UTC | |
by CColin (Scribe) on Jan 21, 2013 at 08:35 UTC | |
by dave_the_m (Monsignor) on Jan 21, 2013 at 11:21 UTC | |
by salva (Canon) on Jan 21, 2013 at 11:52 UTC | |
by CColin (Scribe) on Jan 21, 2013 at 12:58 UTC | |
|