Linux下的文件遍历和Windows下的文件遍历示例
来源:互联网 发布:淘宝刷运费险 编辑:程序博客网 时间:2024/06/06 01:42
来自:http://blog.163.com/tiger_zl2005/blog/static/56329720072141332843/
1.Linux下的目录遍历函数
int num=0;
int i=0;
int j = 0;
int k=0;
int dir_len=0;
int m=0;
char temp[MAX_PATH_LEN];
struct dirent **namelist ;
struct stat statbuf = {0};
char dir[200] = "./";
char Pattern[200] = "";
if(path == NULL)
return FALSE;
num = scandir(path, &namelist, 0, alphasort);
if(-1 != num)
{
/*Get Directory*/
for(i = 0; i < num; i++)
{
if(!strcmp(namelist[i]->d_name,".")||!strcmp(namelist[i]->d_name,".."))
{
continue;
}
sprintf(dir,"%s/%s",path,namelist[i]->d_name);
if(-1 != stat(dir, &statbuf))
{
if(S_ISDIR(statbuf.st_mode))
{
对应的目录处理过程
递归调用自己实现广度遍历 }
}
else
{
对文件的处理过程
}
}
2.Windows下的目录遍历函数
struct _finddata_t filefind;
char curr[MAX_PATH_LEN];
char xing[]="*.*";
int done = 0,m=0;
int handle;
int i = 0;
strcpy(curr,path);
strcat(curr,"\\*.*");
if((-1) ==(handle = _findfirst(curr,&filefind)))
{
return FALSE;
}
while(!(done = _findnext(handle,&filefind)))
{
if(!strcmp(filefind.name,".")||!strcmp(filefind.name,".."))
{
continue;
}
if (_A_SUBDIR & filefind.attrib)
{
对应的目录处理过程
递归调用自己实现广度遍历 }
else
{
对文件的处理过程
}
}
_findclose(handle);
#endif
需要用到目录遍历的朋友请不要忘了添加头文件<dirent.h>到你的头文件中
参考网络资料 其基本实现代码如下
DIR *pDir;
struct dirent *findfile;
struct stat subDir;
pDir=opendir(searchPath);
if (pDir == NULL)
{
return -1 ;
}
do
{
if(!strcmp(findfile->d_name,".") || !strcmp(findfile->d_name,".."))
{
continue;
}
if (stat(searchPath, &subDir) != -1 )
{
if ( S_ISDIR( subDir.st_mode) )
{
if(strcmp(findfile->d_name,"Word") == 0)
{
return 1;
}
}
else
{
}
}
}while(( findfile = readdir( pDir ) ) != NULL);
closedir(pDir);
1.Linux下的目录遍历函数
int num=0;
int i=0;
int j = 0;
int k=0;
int dir_len=0;
int m=0;
char temp[MAX_PATH_LEN];
struct dirent **namelist ;
struct stat statbuf = {0};
char dir[200] = "./";
char Pattern[200] = "";
if(path == NULL)
return FALSE;
num = scandir(path, &namelist, 0, alphasort);
if(-1 != num)
{
/*Get Directory*/
for(i = 0; i < num; i++)
{
if(!strcmp(namelist[i]->d_name,".")||!strcmp(namelist[i]->d_name,".."))
{
continue;
}
sprintf(dir,"%s/%s",path,namelist[i]->d_name);
if(-1 != stat(dir, &statbuf))
{
if(S_ISDIR(statbuf.st_mode))
{
对应的目录处理过程
递归调用自己实现广度遍历 }
}
else
{
对文件的处理过程
}
}
2.Windows下的目录遍历函数
struct _finddata_t filefind;
char curr[MAX_PATH_LEN];
char xing[]="*.*";
int done = 0,m=0;
int handle;
int i = 0;
strcpy(curr,path);
strcat(curr,"\\*.*");
if((-1) ==(handle = _findfirst(curr,&filefind)))
{
return FALSE;
}
while(!(done = _findnext(handle,&filefind)))
{
if(!strcmp(filefind.name,".")||!strcmp(filefind.name,".."))
{
continue;
}
if (_A_SUBDIR & filefind.attrib)
{
对应的目录处理过程
递归调用自己实现广度遍历 }
else
{
对文件的处理过程
}
}
_findclose(handle);
#endif
需要用到目录遍历的朋友请不要忘了添加头文件<dirent.h>到你的头文件中
参考网络资料 其基本实现代码如下
DIR *pDir;
struct dirent *findfile;
struct stat subDir;
pDir=opendir(searchPath);
if (pDir == NULL)
{
return -1 ;
}
do
{
if(!strcmp(findfile->d_name,".") || !strcmp(findfile->d_name,".."))
{
continue;
}
if (stat(searchPath, &subDir) != -1 )
{
if ( S_ISDIR( subDir.st_mode) )
{
if(strcmp(findfile->d_name,"Word") == 0)
{
return 1;
}
}
else
{
}
}
}while(( findfile = readdir( pDir ) ) != NULL);
closedir(pDir);
- Linux下的文件遍历和Windows下的文件遍历示例
- Linux下的文件遍历和Windows下的文件遍历示例
- linux下遍历文件夹下的文件
- Qt文件遍历在linux下和windows下的差异
- C++实现Linux和Windows下遍历指定目录下的文件
- linux遍历文件夹下的文件
- linux遍历目录下的文件
- LINUX下目录文件的遍历---编程
- linux 遍历目录下的文件
- 遍历目录下的文件和文件夹
- 遍历目录下的文件和子目录下的文件
- 遍历目录下的文件
- 遍历文件夹下的文件
- 遍历目录下的文件
- 遍历目录下的文件
- windows下C++文件遍历
- Windows下遍历文件目录
- Linux下遍历目录下的文件 2
- 排序算法总结
- 正则表达式30分钟入门教程
- oracle表分区详解
- CreateStatic CreateView
- Linux TC流量控制HOWTO中文版
- Linux下的文件遍历和Windows下的文件遍历示例
- 在linux系统下,简单实现类似windows的_splitpath函数的功能
- undefined reference to `__gxx_personality_v0'
- qt 中鼠标落点区域判断方法
- 深入浅出之正则表达式(一)
- 深入浅出之正则表达式(二)
- 在Qt中如何判断鼠标离开某一操作的时候,在时间差内自动执行某一个操作
- UITableView +下拉刷新(Pull-refresh)
- 【JavaScript】Cookie