|
|
发表于 2006-4-28 19:02:21
|
显示全部楼层
从我的一个程序COPY过来的.<<UNIX环境高级编程>>有说
void mapinfo::myfindfile(list<string> *needfile) //find file function
{
DIR *sp;
struct dirent *dirp;
struct stat buf;
char *pathname,*newpathname,*ptr,*fullname,*tempstr;
long lens,newlen,fulllen,templen;
string newline;
ptr=fullpath+strlen(fullpath);
*ptr++='/';
*ptr=0;
sp=opendir(fullpath);
if(sp!=NULL)
{
while((dirp=readdir(sp))!=NULL)
{
strcpy(ptr,dirp->d_name);
if(lstat(fullpath,&buf)<0)
{
continue;
}
if(S_ISDIR(buf.st_mode))
{
if(strcmp(dirp->d_name,".")==0 || strcmp(dirp->d_name,"..")==0)
{
continue;
}
myfindfile(needfile);
}
if(S_ISREG(buf.st_mode))
{
if(isfile(dirp->d_name)==true)
{
newline=fullpath;
// cout<<newline<<endl;
needfile->createlist(newline);
}
}
else
{
continue;
}
}
}
if(closedir(sp)<0)
{
printf("close dir failed");
}
} |
|