in reply to Quickest way to get the oldest file
-derby#!/usr/bin/perl use IO::Dir; tie %dir, 'IO::Dir', "."; # assume ctime is close enough for creation time foreach (sort { $dir{$b}->ctime <=> $dir{$a}->ctime } keys %dir ) { print $_, " " , $dir{$_}->ctime,"\n"; }
update: Of course jweed got what I was talking about (admittedly in a round-a-bout way). The OP wanted the oldest created file. In *Nix world, you cannot do that. There are three times associated with a file - last access, last modified and last change time. The -M solutions that follow will work as long as your concept of modification and creation are the same. I can create a file on Jan 1st, another on June 1. If I modify the Jan 1st file (and possibly in some non-significant manner) on Aug 1, then by the -M method, the Jan 1 file will be newer than the June 1 file. See - it all depends on how you define oldest. If your files are created but never modified (such as a caching scheme) then the -M works fine; however, if there is a chance that the files will be modified and you don't count the modifications as making the file newer then checking the ctime is probably better. But then again, that can have issues to ... so that's why I normally suggest a naming convention (date/time) to remove ambiguity.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Quickest way to get the oldest file
by jweed (Chaplain) on Jan 19, 2004 at 21:51 UTC |