码迷,mamicode.com
首页 > 系统相关 > 详细

linux c 遍历目录及文件

时间:2017-11-07 16:27:17      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:continue   clu   name   bsp   文件   har   rcm   cups   move   

#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 遍历目录及文件

标签:continue   clu   name   bsp   文件   har   rcm   cups   move   

原文地址:http://www.cnblogs.com/wangjian8888/p/7799277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!