dilip_val has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am trying to find the age of a directory in windows ,
a and use the same to move it to a different loaction
The below code works for finding age of files greater than 10 days old , making use File::Find
but is there a -d switch which i can use instaed of -f ?
sub _filewanted {
if ( ((-M $_) > 10) && -f $_ ) { # files, not directories
push @files, $File::Find::name;
} }
  • Comment on How do we find the age of a directory ??

Replies are listed 'Best First'.
Re: How do we find the age of a directory ??
by prasadbabu (Prior) on Nov 01, 2007 at 05:25 UTC

    dilip_val,

    Yes, you can use '-d', which checks for the directory.

    Take a look at "-X FILEHANDLE" in perlfunc

    Prasad

      "-d" works , but the script i am using , it picks up the parent directory too.
      So it moves F:\test itself into the destination directory
      but i want only the directories within F:\test and
      and older than 10 days to be moved to F:\old
      SCRIPT is below :-
      use File::stat;
      use Time::localtime;
      use File::Find;
      my @files = ();
      my @paths = ();
      my $dir = 'F:\\test';
      print "Dir - $dir \n";
      find(\&_filewanted, $dir);
      if (@dirs < 1) {
      print "\n There are no files older than 10 days \n";
      } else {
      print "\nThe Following files are older than 10 days and are
      being moved\n";
      for my $file ( @dirs ) {
      $file =~ s/\//\\/;
      print " FILE NAME : $file\n";
      system("move $file F:\\old");
      print "Moved $file to F:\\old\n";
      }
      }
      print "\n";
      sub _filewanted {
      if ( ((-M $_) > 10) && -d $_ ) { # directories not files
      push @dirs, $File::Find::name;
      }
      }