in reply to File list by date

Something like this perhaps...

opendir(ROOT, $dir) || die "$!\n"; foreach (sort { -M $b <=> -M $a } readdir(ROOT) ) { print "$_\n"; }

Update: snax below quite rightly points out a bug in this code.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re: Re: File list by date
by snax (Hermit) on Dec 21, 2000 at 21:05 UTC
    Careful! Checking the description of readdir it says one must either chdir or prepend the $dir if you want to do filetests.
    foreach (sort {-M qq($dir/$b) <=> -M qq($dir/$a)} readdir(ROOT)) { print $_, $/; }
    for example.

      Using this method (snax), is there a way to only list files that are one hour old, or two hours old, etc.?
        Nope :)

        For OS ways to do this, the *nix answer is to use find and sort. Perl is definitely a reasonable way to go when you want this kind of response.

        I usually pipe ls -lt through head -N to just see the more recent files, though, and vary N as necessary.

        But then again, I'm lazy :)