读书人

遍历目录遇到的有关问题

发布时间: 2012-05-12 15:39:31 作者: rapoo

遍历目录遇到的问题。

C/C++ code
string  List(const char *path){  struct dirent* ent = NULL;  DIR *p_dir;  p_dir = opendir(path);  if(p_dir == NULL)    {      return 0;    }  while (NULL != (ent = readdir(p_dir)))    {      //我如何知道p_dir中有哪些子目录?      //假如p_dir中有三个子目录  a,b,c,我如何进入子目录?    }}int main(){   List("/home/yxz");}    


[解决办法]
探讨
引用:

system("dir /b /a-d c:\\*.* >d:\\allfiles.txt");
//读文件d:\\allfiles.txt的内容即C:\\下所有文件的名字
system("dir /b /ad c:\\*.* >d:\\alldirs.txt");
//读文件d:\\alldirs.txt的内容即C:\\下所有子目录的名字
请记住,能用she……

读书人网 >PB

热点推荐