void listDir(char *path)
{
DIR *pDir ;
struct dirent *ent ;
int i=0 ;
char childpath[512];
char childfile[512];
pDir=opendir(path);
memset(childpath,0,sizeof(childpath));
while((ent=readdir(pDir))!=NULL)
{
if(ent->d_type & DT_DIR)
{
if(strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0)
continue;
sprintf(childpath,"%s/%s",path,ent->d_name);
listDir(childpath);
}
else
{
sprintf(childfile,"%s/%s",path,ent->d_name);
}
}
closedir(pDir);
}
遍历文件夹下所有子目录下的文件(linux C )
最新推荐文章于 2023-08-20 16:24:43 发布
本文介绍了一段用C语言编写的函数,voidlistDir(),用于遍历指定路径下的目录及文件,包括递归处理子目录。它通过opendir(), readdir()和closedir()函数实现,适合理解文件系统操作的基本原理。
摘要由CSDN通过智能技术生成