in reply to Finding Oldest File in a Directory

If you're on *nix, you don't need that. Just use:
ls -t | head -1
in the shell/at the command line. (That is a "dash one", not a "dash lowercase ell" on the head command, BTW.)

--
tbone1, YAPS (Yet Another Perl Schlub)
And remember, if he succeeds, so what.
- Chick McGee

Replies are listed 'Best First'.
Re^2: Finding Oldest File in a Directory
by Moron (Curate) on Oct 06, 2005 at 09:21 UTC
    almost...
    ls -t *BOT* | head -1
    or converted to a one liner in perl...
    perl -e 'my %bot; for ( sort { ( $bot{ $a } ||= ( -M $a ) ) <=> ( $bot +{ $b } ||= ( -M $b ) ) } glob "\*BOT\*" ) { print "$_\n"; last; }'

    -M

    Free your mind

      almost...
      ls -td *BOT* | head -1
      Or you'll get the first file in the oldest directory containing BOT in its name (assuming no file whose name contains BOT is older)

      This still has the possibility of returning a directory name though. Under Unix, this still is a file, although when people say "file", they usually want to exclude directories.

      Perl --((8:>*
        No, the -d option specifically limits the output to directories only, not its absence as you imply.

        -M

        Free your mind

Re^2: Finding Oldest File in a Directory
by Aristotle (Chancellor) on Oct 08, 2005 at 19:30 UTC

    Except you need tail, because ls -t lists the files from newest to oldest.

    And beware of filenames with embedded newlines, they will get cut in half by the tail and you might end up manipulating a file other than the one you wanted.

    Makeshifts last the longest.