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

Using sort and readdir (see snax reply to "file list by date"), is there a way to only list files created within the last two hours, for example? I'm looking for something with higher resolution than the find -mtime command.

Replies are listed 'Best First'.
Re: only list recent files
by merlyn (Sage) on May 03, 2001 at 19:13 UTC
Re: only list recent files
by japhy (Canon) on May 03, 2001 at 19:13 UTC
    Use the -M file test on the files.
    opendir DIR, $path or die "can't open $path: $!"; while (defined(my $f = readdir DIR)) { push @ok, [ "$path/$f", -M _ ] if (24 * -M "$path/$f") <= 2; } closedir DIR;
    Now you can sort on the second element of the array references. The reason I multiply the return value of the modification time is because it returns the time in days. So I turn that into hours.

    Just so you know, you can never know when a file on a Unix system was created. It's just not supported.

    japhy -- Perl and Regex Hacker