You are here: RE: [PHP] Find largest integer filename « PHP « IT news, forums, messages
RE: [PHP] Find largest integer filename

Posted by "Michael Sims" on 07/06/05 08:28

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация