Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The attrib parameter in findfirst 1

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo - there is a folder called D:\Downloads\Files, and in this folder are several subfolders and a number of files.
The following code, with attrib as FA_DIREC, should only show the names of the subfolders, but I keep getting the files as well.

ffblk ffblk;
int result=findfirst("D:\\Downloads\\Files\\*",ffblk,FA_DIREC);
while(result==0){
ShowMessage(ffblk.ff_name);
result=findnext(ffblk.ff_name);
}

Does anybody know why?

Cheers,
Douglas JL Common sense is what tells you the world is flat.
 
I had the same problem a while ago, could not find the reason.
I made a work around, out of my head, it can give some compile error:

if( ffblk.attrib & FA_DIREC ) {
// do what you want to do with directoy: ffblk.ff_name
}
 
Thanks - I'll give it a try.
Cheers,
Douglas JL Common sense is what tells you the world is flat.
 
or was it:
if( ( ffblk.attrib & FA_DIREC ) == FA_DIREC ) {

I have the source code at home, will let you know asap
 
That'd be fantastic, thanks Common sense is what tells you the world is flat.
 
hi Douglas,

My second post contained the proper code.
I have used the code below to do a recursive directory scan.

best of luck,
Hennie


void TfrmCTdir::ScanDir( char *sDir, char *sWild ) {
// example: ScanDir( "c:\\", "*.*" );
struct ffblk ffblk;
int done;
char sTmp[512], sTmp2[512];

strcpy( sTmp, sDir );
strcat( sTmp, sWild );
done = findfirst( sTmp, &ffblk, FA_DIREC + FA_SYSTEM + FA_HIDDEN + FA_RDONLY + FA_ARCH );
while( !done && !frmScan->Abort ) {
if( strcmp( ".", ffblk.ff_name ) != 0
&& strcmp( "..", ffblk.ff_name ) != 0 ) {
if( (ffblk.ff_attrib & FA_DIREC) == FA_DIREC ) {
// process directory
strcpy( sTmp, sDir );
strcat( sTmp, ffblk.ff_name );
strcat( sTmp, "\\" );
if( frmCTdir->GetProperty("RECURS") ) {
ScanDir( sTmp, sWild );
if( frmScan->Abort ) {
break;
}
}
} else {
// process file
}
}
done = findnext(&ffblk);
}
}
 
That totally solves my problem (twice in one day!) - thanks again for your help.
Cheers,
Douglas JL Common sense is what tells you the world is flat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top