tags:

views:

78

answers:

3
[root@file nutch-0.9]# ls resume/
crawldb  index  indexes  linkdb  segments

like the above example,

how to get number of sub files(can be file or directory) in PHP?

A: 

The examples for readdir are most probably what you are looking for.

Alan Haggai Alavi
+1  A: 

use the PHP function readdir or scandir in PHP, get the file list as an array and get a count on the array. you may have to do some tweaking to avoid the current and parent directory ( . and .. )

http://us3.php.net/manual/en/function.readdir.php

http://us3.php.net/manual/en/function.scandir.php

Roy Rico
+1  A: 
function count_files($path) {
    return count(array_diff(scandir($path), array(".", "..")));
}
phihag
that will include . and .. and why do you return 1 if it's not a directory?
SilentGhost
as well as any hidden files, which ls doesn't show by default
SilentGhost
@SilentGhost Fixed. And I thought (can be file or directory) referred to the argument. Obviously, it does not.
phihag