linux c 扫描文件目录
来源:互联网 发布:手机双卡怎么设置网络 编辑:程序博客网 时间:2024/06/01 14:54
/*
* printdir.c
*
* Created on: Apr 6, 2013
* Author: jwang
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
void printdir(char *dir, int depth);
int main(int argc, char **argv) {
printf("Directory scan of /home:\n");
printdir("/home", 0);
printf("done.\n");
exit(0);
}
/**
* 输出文件夹信息
*/
void printdir(char *dir, int depth) {
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if ((dp = opendir(dir)) == NULL) {
fprintf(stderr, "cannot open directory : %s\n", dir);
return;
}
chdir(dir);
while ((entry = readdir(dp)) != NULL) {
lstat(entry->d_name, &statbuf);
if (S_ISDIR(statbuf.st_mode)) {
/* Found a directory, but ignore . and .. */
if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name)
== 0) {
continue;
}
printf("%*s%s/\n", depth, "", entry->d_name);
/* Recurse at a new indent level */
printdir(entry->d_name, depth + 4);
} else {
printf("%*s%s\n", depth, "", entry->d_name);
}
}
chdir("..");
closedir(dp);
}
* printdir.c
*
* Created on: Apr 6, 2013
* Author: jwang
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
void printdir(char *dir, int depth);
int main(int argc, char **argv) {
printf("Directory scan of /home:\n");
printdir("/home", 0);
printf("done.\n");
exit(0);
}
/**
* 输出文件夹信息
*/
void printdir(char *dir, int depth) {
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if ((dp = opendir(dir)) == NULL) {
fprintf(stderr, "cannot open directory : %s\n", dir);
return;
}
chdir(dir);
while ((entry = readdir(dp)) != NULL) {
lstat(entry->d_name, &statbuf);
if (S_ISDIR(statbuf.st_mode)) {
/* Found a directory, but ignore . and .. */
if (strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name)
== 0) {
continue;
}
printf("%*s%s/\n", depth, "", entry->d_name);
/* Recurse at a new indent level */
printdir(entry->d_name, depth + 4);
} else {
printf("%*s%s\n", depth, "", entry->d_name);
}
}
chdir("..");
closedir(dp);
}
- linux c 扫描文件目录
- Linux文件操作-->扫描目录
- linux扫描目录下所有文件
- linux下c/c++实例之七递归扫描目录下的文件
- linux下c/c++实例之七递归扫描目录下的文件
- 扫描目录文件
- linux目录扫描
- Linux C目录与文件
- Linux目录扫描:打印指定目录下的所有文件及目录
- 目录扫描 C语言实现
- Java扫描指定目录文件
- 扫描目录下所有文件
- linux c目录与普通文件
- [Linux]C语言遍历文件和目录
- Linux C编程--目录文件操作
- Linux使用C读取文件目录
- [Linux]C语言遍历文件和目录
- Linux - 打印目录所有文件 代码(C)
- 基于Eclipse的Hadoop应用开发环境配置
- JAVA 使用httpclient、XFire方式调用Web Service的方法
- win7 64位下如何安装配置mysql + 系统找不到指定的文件问题
- Android之ListView
- 乘法表
- linux c 扫描文件目录
- 防伪码
- 从人人网客户端看Win8 Metro设计精髓
- 字符串
- Jquery-dataTables
- 相似图片搜索原理
- Android之进度条的使用
- cp: omitting directory”错误的解释和解决办法
- android ndk开发,fatal错误记录