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

遍历目录

void CConfigfile::GerConfigFile(const char *strpath)
{
char dir[MAX_PATH] = {0};
char childpath[MAX_PATH] = {0};
DIR *dp; // 定义子目录流指针
struct dirent *entry; // 定义dirent结构指针保存后续目录
struct stat statbuf; // 定义statbuf结构保存文件属性
strcpy(dir, strpath);
if((dp = opendir(dir)) == NULL) // 打开目录,获取子目录流指针,判断操作是否成功
{
puts("can't open dir.");
return;
}
//chdir (dir); // 切换到当前目录
while((entry = readdir(dp)) != NULL) // 获取下一级目录信息,如果未否则循环
{
lstat(entry->d_name, &statbuf); // 获取下一级成员属性
if(S_IFDIR &statbuf.st_mode) // 判断下一级成员是否是目录
{
if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)
continue; sprintf(childpath,"%s/%s",strpath,entry->d_name);
printf("path:%s\n",childpath);
GerConfigFile(childpath);
//printf("%*s%s/\n", depth, "", entry->d_name); // 输出目录名称
//scan_dir(entry->d_name, depth+4); // 递归调用自身,扫描下一级目录的内容
}
else
{ }
//printf("%*s%s\n", depth, "", entry->d_name); // 输出属性不是目录的成员
}
//chdir(".."); // 回到上级目录
closedir(dp); // 关闭子目录流
return;
}

  

linux c 遍历目录及文件的更多相关文章

  1. Linux下遍历目录及文件,更改权限

    Linux下遍历目录及文件,更改权限 引言: 我在Linux下搭建android时,将eclipse及sdk复制到/usr/下时,总会出现无法读,无法写写样的问题. 解决方案: 有两个方案: 一.将复 ...

  2. linux C遍历目录下文件

    参考链接: http://blog.sina.com.cn/s/blog_626b7339010161tr.html

  3. 【app】遍历目录所有文件

    遍历目录所有文件   原创,转载时请注明,谢谢.邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:htt ...

  4. Linux中/proc目录下文件详解

    转载于:http://blog.chinaunix.net/uid-10449864-id-2956854.html Linux中/proc目录下文件详解(一)/proc文件系统下的多种文件提供的系统 ...

  5. php遍历目录下文件,并读取内容

    <?php echo "<h2>遍历目录下文件,并读取内容</h2><br>\n"; function listDir($dir) { i ...

  6. linux下为目录和文件设置权限

    摘:linux下为目录和文件设置权限 分类: Linux2012-05-09 03:18 7456人阅读 评论(1) 收藏 举报 linuxwordpressweb数据库serverfile linu ...

  7. Linux中/proc目录下文件详解(转贴)

      转载:http://www.sudu.cn/info/index.php?op=article&id=302529   Linux中/proc目录下文件详解(一) 声明:可以自由转载本文, ...

  8. dos下遍历目录和文件的代码(主要利用for命令)

    对指定路径指定文件进行遍历的程序,这里有多个批处理代码,但运行好像有些问题,大家可以根据需要选择 ===== 文件夹结构 ======================================= ...

  9. dos下遍历目录和文件的代码(主要利用for命令)(转)

    ===== 文件夹结构 ============================================= D:\test ---A Folder 1 |-----A file 1.txt | ...

随机推荐

  1. springcloud微服务总结六

    SpringCloud实战7-Config分布式配置管理 分布式环境下的统一配置框架,已经有不少了,比如百度的disconf,阿里的diamand 官方文档对spring Cloud Config的描 ...

  2. Qt 学习之路 2(63):使用 QJson 处理 JSON

    Home / Qt 学习之路 2 / Qt 学习之路 2(63):使用 QJson 处理 JSON Qt 学习之路 2(63):使用 QJson 处理 JSON  豆子  2013年9月9日  Qt ...

  3. [Beta阶段]第一次Scrum Meeting

    Scrum Meeting博客目录 [Beta阶段]第一次Scrum Meeting 基本信息 名称 时间 地点 时长 第一次Scrum Meeting 19/04/29 大运村寝室6楼 70min ...

  4. wepsocket 了解一下

    WebSocket协议是基于TCP的一种新的协议.WebSocket最初在HTML5规范中被引用为TCP连接,作为基于TCP的套接字API的占位符.它实现了浏览器与服务器全双工(full-duplex ...

  5. java的Spring学习3- mybatis

    1.java的maven依赖包 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourc ...

  6. C++ STL之Set

    set是关联容器,类似于集合. 特点是里面的元素不会重复,而且元素时有序的. 1.声明定义: #include<set> using namespace std; set<int&g ...

  7. UML类图关系(继承、泛化、实现、依赖、关联、聚合、组合)

    继承.实现.依赖.关联.聚合.组合的联系与区别 分别介绍这几种关系: 继承 指的是一个类(称为子类.子接口)继承另外的一个类(称为父类.父接口)的功能,并可以增加它自己的新功能的能力,继承是类与类或者 ...

  8. Eclipse for PHP Developers 配置记录

    [原文发表在 http://osworld.sinaapp.com/post/18.html] 图都粘贴不了,直接看上面的原文吧~~~ 我比较懒,还是比较依赖IDE环境做开发的.所以为了学PHP开发, ...

  9. js - cannot set property xxx of undefined

    for(let i=0;i<=res.data.length;i++){ res.data[i]['class'] = 'biaoqian-red'; } console.log(res.dat ...

  10. Kafka消费不到数据的特殊情况

    我大约是把kafka消费不到数据的特殊情况都经历了一遍了吧= =. kafka消费不到数据的原因,首先检查配置之类的,如是否设置了group.id,对应的topic是否正确等等,这些不多说. 下面是我 ...