Win32::ChangeNotify;

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • homesick123
    New Member
    • Oct 2006
    • 8

    Win32::ChangeNotify;

    Hi

    How can I use Win32::ChangeNo tify; to get the path of the last modified file in a sub-sub-sub-directory under $Path directory?

    Thanks
  • homesick123
    New Member
    • Oct 2006
    • 8

    #2
    Originally posted by homesick123
    Hi

    How can I use Win32::ChangeNo tify; to get the path of the last modified file in a sub-sub-sub-directory under $Path directory?

    Thanks
    Is there any other method of doing that?

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      It sounds like what you really need is File::Find. This module basically recurses through an entire directory tree, letting you do whatever manipulations you want at each step. In this instance, there would simply be utilizing the -M operator to determine the age of a file in days, and constantly updating your value at each step. I've included working code below that simply takes a directory location from the command prompt.

      Code:
      #!/usr/bin/perl
      
      use strict;
      
      use File::Find;
      
      my $dir = @ARGV ? $ARGV[0] : '.';
      
      my @files = ();
      my $modified = -1;
      
      find(sub {
      	my $m = -M $File::Find::name;
      	
      	if ($m == $modified) {
      		push @files, $File::Find::name;
      	} elsif ($modified == -1 || $m < $modified) {
      		@files = $File::Find::name;
      		$modified = $m;
      	}
      }, $dir);
      
      print "The youngest files are $modified days old: " . join('', map {"\n\t$_"} @files) . "\n";
      
      1;
      
      __END__

      Comment

      Working...