linux c 遍历目录及文件
#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 遍历目录及文件的更多相关文章
- Linux下遍历目录及文件,更改权限
Linux下遍历目录及文件,更改权限 引言: 我在Linux下搭建android时,将eclipse及sdk复制到/usr/下时,总会出现无法读,无法写写样的问题. 解决方案: 有两个方案: 一.将复 ...
- linux C遍历目录下文件
参考链接: http://blog.sina.com.cn/s/blog_626b7339010161tr.html
- 【app】遍历目录所有文件
遍历目录所有文件 原创,转载时请注明,谢谢.邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:htt ...
- Linux中/proc目录下文件详解
转载于:http://blog.chinaunix.net/uid-10449864-id-2956854.html Linux中/proc目录下文件详解(一)/proc文件系统下的多种文件提供的系统 ...
- php遍历目录下文件,并读取内容
<?php echo "<h2>遍历目录下文件,并读取内容</h2><br>\n"; function listDir($dir) { i ...
- linux下为目录和文件设置权限
摘:linux下为目录和文件设置权限 分类: Linux2012-05-09 03:18 7456人阅读 评论(1) 收藏 举报 linuxwordpressweb数据库serverfile linu ...
- Linux中/proc目录下文件详解(转贴)
转载:http://www.sudu.cn/info/index.php?op=article&id=302529 Linux中/proc目录下文件详解(一) 声明:可以自由转载本文, ...
- dos下遍历目录和文件的代码(主要利用for命令)
对指定路径指定文件进行遍历的程序,这里有多个批处理代码,但运行好像有些问题,大家可以根据需要选择 ===== 文件夹结构 ======================================= ...
- dos下遍历目录和文件的代码(主要利用for命令)(转)
===== 文件夹结构 ============================================= D:\test ---A Folder 1 |-----A file 1.txt | ...
随机推荐
- ionic4 添加自定义字体图标
在angular.json中的style中引入css文件: 然后在variables.scss中添加内容:
- 【KMP】洛谷P2375 [NOI2014]动物园 题解
一开始的方向应该对了,但是没有想到合理的优化还是没写出来…… 题目描述 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己 ...
- [转] 前后端分离之JWT用户认证
[From] http://www.jianshu.com/p/180a870a308a 在前后端分离开发时为什么需要用户认证呢?原因是由于HTTP协定是不储存状态的(stateless),这意味着当 ...
- 批量删除Maven中失败的下载项
[摘自] http://stackoverflow.com/questions/5074063/maven-error-failure-to-transfer Remove all your fail ...
- poj3262
一.题意:有n头牛,每头牛每分钟会吃D个菜,把这头牛赶回去需要时间T(人再返回又需要T),一次只能赶回去一头牛,也就是说剩下的牛会继续吃菜.求牛最少吃多少菜 二.思路:贪心.按D/T将牛进行排序,然后 ...
- protobuf参考
https://www.cnblogs.com/chenyangyao/p/5422044.html
- API 接口收集
节假日 http://api.goseek.cn/ http://timor.tech/api/holiday http://www.easybots.cn/api/holiday.php?d=201 ...
- 问题记录——java.lang.IllegalArgumentException: Illegal character in scheme name at index 0
以下http请求报错是因为,请求的地址前面有个空格.... 2019-01-09 03:30:23,154 ERROR [business.modules.merchantreportresult.s ...
- 2019.03.26 读书笔记 关于event
event 主要是给委托加了一层保护,不能任意的 class.delegate=null,class.delegate=fun1,不能由调用者去任意支配,而是由class自己去增加或减少,用+=.-= ...
- python 爬虫系列02-小说
本爬虫为网络上的.. # # -*- coding:UTF-8 -*- # from bs4 import BeautifulSoup # import requests # if __name__ ...