Re: findFirstFile, findNextFike by nobody
nobody
Sat Aug 20 07:11:13 CDT 2005
I just did something like that a few weeks ago:)
_MAX_PATH is 260
_finddata_t fileinfo;
char localPath2[_MAX_PATH];
char localPath[_MAX_PATH];
intptr_t fHandle = _findfirst(path,&fileinfo);
do
{
if((fileinfo.attrib & _A_SUBDIR))
{
//do printf
if((strcmp(fileinfo.name,".")==0)||
(strcmp(fileinfo.name,"..")==0))
{
//do printf
}
else continue;
//. and .. cause resursion so skip them.
}
if(bResurse)
{
//move to child directory
if(_chdir(fileinfo.name)==-1)
{
cout<<"error _chdir"<<endl;
break;
}
if(_getcwd(localPath,MAX_PATH)==NULL)
{
cout<<"error _getcwd"<<endl;
break;
}
else
{
strcpy(localPath2,localPath);
strcat(localPath2,"\\");
}
//recursive call here
}
}while(!_findnext(fHandle,&fileinfo))
It works somewhat like that. Look at _findfirst, also it
accepts wildcards I believe.
Things Thousand delimiter:
char* ThousandDelimitor(int nInput)
{
bool done=false;
int nCounter=0;
char* ptrCh, *ptrCh2;
static char str[15], strTmp[15];
ptrCh = strTmp;
for(int i = 10; nInput>0;)
{
*ptrCh++ = (char)(nInput % i) + '0';
nInput /= 10; //get rid of one digit since
this division with no reminder
if (nInput && !(++nCounter % 3))
*ptrCh++ = ',';
}
//reverse the string
for( --ptrCh, ptrCh2 = str; ptrCh >= strTmp; --
ptrCh)
*ptrCh2++ = *ptrCh;
// add the zero string terminator
*ptrCh2 = '\0';
return str;
}
Also you might want to keep track of fileinfo if you want
to print the column in nicely spaced manner like under
dos wih "dir" command. You can't get this effect if you
don't know the largest filename or largest size. I use
additional helper function to look through files again (I
don't see how you can skip looping through everything
twice if you need the formatting).
have fun