Igor Sutton Lopes wrote:
> 
> On Apr 10, 2007, at 3:27 PM, John W. Krahn wrote:
> 
>> Craig Schneider wrote:
>>
>>> How could I exec a 'dir' command on a dos system and put the  output in
>>> an array, sort by date and the files that are older than 3 days be 
>>> moved into a folder called 'history'
>>
>> # open the current directory
>> opendir my $dh, '.' or die "Cannot open '.' $!";
>>
>> # get files older than three days
>> my @files = grep -M > 3, readdir $dh;
>>
>> closedir $dh;
>>
>> for my $file ( @files ) {
>>     rename $file, "history/$file" or die "Cannot move '$file' $!";
>>     }
> 
> You can also use File::Find::Rule for that:
> 
> <code>
> use strict;
> use warnings;
> 
> use File::Copy;
> use File::Find::Rule;
> use File::Spec;
> 
> my $basedir = "/Users/igorsutton/workspace";
> 
> sub move_file {
>     move( $_[2], File::Spec->catdir( $basedir, 'history', $_ ) )
>       or warn $!;
> }
> 
> my $rule = File::Find::Rule->new;
> $rule->directory()->name('trunk')->exec( \&move_file )->in($basedir);
> </code>

Did you test this?  Where do you distinguish between files "older than 3 days"
and other files?  Where is "name('trunk')" specified by the OP?



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to