void listDir(char *dirpath)
{
DIR *dir = opendir((const char*)dirpath);
if(dir == NULL)
{
printf("open the log directory <%s> failure\n",dirpath);
return ;
}
struct dirent *dirp = NULL;
while((dirp = readdir(dir)) != NULL)
{
if(dirp->d_type & DT_DIR)
{
printf("dirpath = %s\n",dirpath);
if(dirp->d_name == NULL || dirp->d_name[0] == '.' || strcmp(dirp->d_name,"..") == 0)
continue;
sprintf(m_chTempPath,"%s%s/",dirpath,dirp->d_name);
listDir(m_chTempPath);
}
else if(dirp->d_type & DT_REG)
{
sprintf(m_chTemp,"%s%s",m_chTempPath,dirp->d_name);
printf("m_chTemp = %s\n",m_chTemp);
}
else
continue;
}
closedir(dir);
}
代码如上,目录结构如下:
/root/shanghai/jingan/xiaoming.txt /root/nanjing/xuanwu/tom.txt
/root/shanghai/changning/xiaohong.txt /root/nanjing/hexi/jack.txt
/root/shanghai/putuoxiaoli.txt /root/nanjing/baixia/may.txt
当我执行程序时,读目录结构会出错,比如会读成 /root/shanghai/jingan/changning,而jingan和changning是并列的两个目录,这种错误该怎么改,急等大大们在线帮解决
慕斯709654
慕沐林林