c语言遍历某文件夹下的所有文件 包括子文件夹
2016-08-28 13:27
465 查看
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;
}
fprintf(stderr,"cannot open directory: %s\n", dir);
chdir(dir);
while((entry = readdir(dp)) != NULL) {
lstat(entry->d_name,&statbuf);
if( S_ISDIR(statbuf.st_mode) ){
if( strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0 ){
continue;
}
LOGE("%*s%s/\n",depth,"",entry->d_name);
if( strcmp("sys",entry->d_name) == 0 || strcmp("proc",entry->d_name) == 0 ){
//ÎļþÌ«ËûÂèµÄ¶àÁË
continue;
}
printdir(entry->d_name,depth+4);
}else{
LOGE("%*s%s\n",depth,"",entry->d_name);
}
}
chdir("..");
closedir(dp);
}
static int recovery_test( void )
{
saved_log_file* head = NULL;
DIR* d;
struct dirent* de;
d = opendir("/");
if( d ){
char path[PATH_MAX];
strcpy(path, "/");
//strcat(path, "/");
int path_len = strlen(path);
while( (de = readdir(d)) != NULL ){
LOGE("de->d_name: %s\n", de->d_name);
if( strncmp(de->d_name, "last", 4) == 0 ){
}
}
closedir(d);
} else {
if (errno != ENOENT) {
LOGE("opendir failed: %s\n", strerror(errno));
}
}
ui->Print("in test\n" );
printdir("/",0);
return 0;
}
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if( (dp = opendir(dir)) == NULL ){
fprintf(stderr,"cannot open directory: %s\n", dir);
return;
}
fprintf(stderr,"cannot open directory: %s\n", dir);
chdir(dir);
while((entry = readdir(dp)) != NULL) {
lstat(entry->d_name,&statbuf);
if( S_ISDIR(statbuf.st_mode) ){
if( strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0 ){
continue;
}
LOGE("%*s%s/\n",depth,"",entry->d_name);
if( strcmp("sys",entry->d_name) == 0 || strcmp("proc",entry->d_name) == 0 ){
//ÎļþÌ«ËûÂèµÄ¶àÁË
continue;
}
printdir(entry->d_name,depth+4);
}else{
LOGE("%*s%s\n",depth,"",entry->d_name);
}
}
chdir("..");
closedir(dp);
}
static int recovery_test( void )
{
saved_log_file* head = NULL;
DIR* d;
struct dirent* de;
d = opendir("/");
if( d ){
char path[PATH_MAX];
strcpy(path, "/");
//strcat(path, "/");
int path_len = strlen(path);
while( (de = readdir(d)) != NULL ){
LOGE("de->d_name: %s\n", de->d_name);
if( strncmp(de->d_name, "last", 4) == 0 ){
}
}
closedir(d);
} else {
if (errno != ENOENT) {
LOGE("opendir failed: %s\n", strerror(errno));
}
}
ui->Print("in test\n" );
printdir("/",0);
return 0;
}
相关文章推荐
- c#遍历一个文件夹下的所有文件包括子文件夹【原】
- c#遍历一个文件夹下的所有文件包括子文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹
- 遍历文件夹,取到一个文件夹下的所有文件包括子文件夹中的文件
- c#遍历一个文件夹下的所有文件包括子文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹(转载)
- linux下 c语言递归遍历文件夹下所有文件和子文件夹(附上替换文本文件内容的方法)
- 遍历文件夹 下的所有文件 ,包括子文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹(转载)
- C#如何遍历一个文件夹下面所有的文件、包括子文件夹里面的文件?
- C#遍历一个文件夹下的所有文件包括子文件夹
- 遍历指定文件夹下的所有文件(包括子文件夹下)
- c#遍历一个文件夹下的所有文件包括子文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹
- c#遍历一个文件夹下的所有文件包括子文件夹
- java读取文件夹下所有文件(包括子文件夹)的文件名
- [python]抓取文件夹的所有文件,包括子文件夹和子文件夹的文件
- C语言遍历文件夹里所有文件【转】
- 遍历文件夹及其子文件夹下所有文件