c_cpp ç遍历文件夹.C
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp ç遍历文件夹.C相关的知识,希望对你有一定的参考价值。
//遍历目录,返回值需外部释放掉空间
char * recursiondir(char* dir)
{
char *file_path_and_name;
char *file_path_getcwd;
file_path_getcwd = (char *)malloc(sizeof(char)*200);
file_path_and_name = (char *)malloc(sizeof(char)*200);
memset(file_path_getcwd,0, sizeof(char)*200);
memset(file_path_and_name,0, sizeof(char)*200);
DIR *dp;
if( (dp = opendir(dir)) == NULL )
{
printf( "open directory: %s failed!\n", dir);
return NULL;
}
chdir(dir);
struct dirent *dirp;
while(NULL != ( dirp = readdir(dp)))
{
struct stat statbuff;
lstat(dirp->d_name, &statbuff);
if(S_ISDIR(statbuff.st_mode))//?是目录->则递归/返回
{
if( strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 )
continue;
recursiondir(dirp->d_name);
}
else
{
if(dirp->d_name[0]=='.') continue;
memset(file_path_getcwd,0, sizeof(char)*200);
memset(file_path_and_name,0, sizeof(char)*200);
getcwd(file_path_getcwd,200);
sprintf(file_path_and_name,"%s/%s",file_path_getcwd, dirp->d_name);
// printf("file_path_getcwd:%s,name:%s\n",file_path_getcwd,dirp->d_name);
// return buff;
// function_path(file_path_and_name);//对路径进行处理时打开
// function_file(dirp->d_name);//对文件进行处理时打开
}//if
}//while
chdir("..");//跳转到上级。
closedir(dp);
free(file_path_and_name);
return file_path_getcwd;
}
以上是关于c_cpp ç遍历文件夹.C的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp ç一次将整个文件读入内存的.c
c_cpp İçiçeforörnekler
c_cpp 你好ç
c_cpp 231.cpp
c_cpp 你好ç
c_cpp ç语言二维数组