影子论坛

发新帖

遍历文件夹 源码

1472580369 4月前 103

typedef int SEARCH_CB(char *path);

//遍历文件夹内容

define MAX 200

int searchDir(char path, SEARCH_CB call)
{
int32 search, find;

//开始搜索
char buff = malloc(sizeof(char)MAX);
memset(buff, '0', MAX);
search = findstart(path, buff, MAX);
find = (unsigned char)search;

//遍历搜索
while(find>=0)
{
//生成新名字
char *newname =
malloc(sizeof(char)*(strlen(path)+MAX));
memset(newname, '0', strlen(path)+MAX);
sprintf(newname, "%s/%s", path, buff);

//转换图片
if(filestate(newname)==IS_FILE)
{
(*call)(newname);
}

//文件夹
if(filestate(newname)==IS_DIR)
if(strcmp(newname, "")!=0)
if(strcmp(buff, ".")!=0)
if(strcmp(buff, "..")!=0)
{
if((*call)(newname))
searchDir(newname, call);
}

//搜索下一个
free(newname);
memset(buff, '0', MAX);
find = findnext(search, buff, MAX);
}

free(buff);
findstop(search);
return FALSE;
}

最新回复 (0)
返回
发新帖
1472580369
主题数
1
帖子数
1
注册排名
495

Processed Time:0.19770812988281