日期:2014-05-16  浏览次数:20584 次

请问哪个函数可以活得目录下文件的数目?
linux下的。。。

谢谢

------解决方案--------------------
scandir
------解决方案--------------------
#include <stdlib.h> ;
#include <stdio.h> ;
#include <sys/types.h> ;
#include <dirent.h> ;


int ListDir(char *pcPath)
{
DIR *pDir;
struct dirent *pDirent;

if((pDir = opendir(pcPath)) == NULL)
{
closedir(pDir);
return -1;
}

while((pDirent = readdir(pDir)) != NULL)
{
printf( "%s\n ", pDirent-> ;d_name);
}
closedir(pDir);

return 1;
}

int main(void)
{
ListDir( "/home ");
return 1;
}

------解决方案--------------------
ls |wc -l