linux c 遍历目录及文件

Posted www

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux c 遍历目录及文件相关的知识,希望对你有一定的参考价值。

#include <dirent.h>
void
recovery_backend() { DIR * pdir ; struct dirent * pdirent; struct stat f_ftime; char full_path[PATH_MAX] = {0}; char buf[PATH_MAX] = {0}; char cmd[256] = {0}; pdir = opendir(cups_backend); if(pdir == NULL) return ; for(pdirent = readdir(pdir);pdirent != NULL;pdirent = readdir(pdir)) { if(strcmp(pdirent->d_name,".")==0||strcmp(pdirent->d_name,"..")==0) continue; memset(full_path,0,sizeof(full_path)); snprintf(full_path,sizeof(full_path),"%s%s",cups_backend,pdirent->d_name); if(stat(full_path,&f_ftime) != 0) if(S_ISDIR(f_ftime.st_mode)) continue; /*子目录跳过*/ if(f_ftime.st_mode & S_IFDIR) continue; memset(buf,0,sizeof(buf)); readlink(full_path,buf,sizeof(buf)); if(strcmp(full_hook_backend,buf) == 0) { remove(full_path); memset(cmd,0,sizeof(cmd)); snprintf(cmd,sizeof(cmd),"cp -P %s%s %s",bk_backend,pdirent->d_name,cups_backend); system(cmd); } } closedir(pdir); }

 


以上是关于linux c 遍历目录及文件的主要内容,如果未能解决你的问题,请参考以下文章

Python中如何遍历指定目录下的所有文件?

linux 下的文件目录操作之遍历目录

C#--遍历目录实例

liunx学习:linux下目录操作大全

PHP遍历并打印指定目录下所有文件实例

二叉树的前序中序和后续遍历及应用场景