当前位置: 代码迷 >> PB >> 遍历目录遇到的有关问题
  详细解决方案

遍历目录遇到的有关问题

热度:26   发布时间:2016-04-29 08:19:10.0
遍历目录遇到的问题。
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……
  相关解决方案