编译模式使用,普通模式需要简单的修改。
递归搜索并且回调,回调路径如需要继续需要手动保存。
//递归内容回调函数
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;
}