RE: Find largest integer filename

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux