您的位置:首页 > 其它

用非递归方式遍历目录及其子目录的文件

2007-01-10 23:20 861 查看
typedef BOOL (*PROCESS_FILE_FUNCTION)(LPCTSTR filename);
上面的PROCESS_FILE_FUNCTION是一种函数指针,这个函数处理文件名为filename的文件,如果该函数返回
FALSE,则ProcessDirectory立刻退出,不再继续查找
void ProcessDirectory(LPCTSTR dirname,PROCESS_FILE_FUNCTION proc)
{
CStringArray dirs;
CString searchname;
CFileFind find;
dirs.Add(dirname);
BOOL bRet;
while(dirs.GetSize()>0)
{

searchname = dirs[0] +"//*.*";
dirs.RemoveAt(0);
bRet = find.FindFile (searchname,0);
if(!bRet)continue;
do{
bRet = find.FindNextFile ();
if(find.IsDots ())
{//忽略.和..文件
continue;
}
if(find.IsDirectory ())
{
dirs.Add (find.GetFilePath());
continue;
}else{
if(!proc(find.GetFilePath ()))
{
return;
}
}
}while(bRet);
}
}

发表于 @ 2006年06月21日 13:56:00 | 评论 (0)



取随机数算法


//先调用它
srand( (unsigned)time( NULL ) ); //随机数计时开始
然后调用
GetRand(float nMin, float nMax)
{
float max;
max=RAND_MAX;
return (int)(rand()*(nMax-nMin)/max+nMin);
}
其中nMin,nMax为你要求的随机数的上下限
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: