RE: [PHP] Find largest integer filename
| From: | Michael Sims | Date: | Wed, 06 Jul 2005 05:28:17 +0000 |
| Subject: | RE: [PHP] Find largest integer filename | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-218175@lists.php.net to get a copy of this message | ||
Richard Lynch wrote:
> Suppose I have a directory with a HUGE number of filenames, all of
> which happen to look like integers:
[...]
> Now, in a PHP script, what's the most efficient way to find the
> "largest" filename, where "largest" means in the sense of an integer,
> not a string?
[...]
> Is there some nifty shell command I should just "exec"?...
How about this:
$output = exec("cd $myDirectory; ls -C -1 | sort -n -r | head -n1");
That's assuming your version of "ls" supports the -C (list entries by
column) and -1 (list one file per line) options. Mine does (Debian stable)
but if you're using a different *nix it may not.
HTH...