I need codes to access all files in all subdirectory in one directory in
VC++/VStudio but in console (DOS) mode. Thank you for your help in advance.
M.K.

Re: findFirstFile, findNextFike by William

William
Thu Aug 18 18:42:12 CDT 2005

"Masao Kishore" <on@request.com> wrote in message
news:bR8Ne.755$5U2.345@lakeread07...
>I need codes to access all files in all subdirectory in one directory in
>VC++/VStudio but in console (DOS) mode. Thank you for your help in advance.
> M.K.

Well, then you will need to write it yourself or search for a such a routine
on the net. The operating system provides for the ability to scan a _single_
directory at a time. You'd need to start at the root of the drive(s) in
question and recurse through the "tree" yourself - i.e start enumerating a
"child" directory whenever you find one in the "parent".

Do not forgot to close all the handles to the enumerations that you open.

Regards,
Will



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