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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search thru SubDirectory?

Status
Not open for further replies.

Bigd1170

Programmer
Joined
Apr 10, 2003
Messages
4
Location
US
Is there a way to search a folder and all of its sub folders with win32 code. I tried to use FileSearch(), but it only searches that folder, not its sub folders.
 
I don't know of a simple component. The way I do it has been discussed in this forum before. You may have to do a search for it. It is basically the same way it was done in DOS. You find the first file (FindFirstFile), check to see if it is a directory (. or ..), it so, go into the directory, and find it first file, see if it is a directory, ect, etc, then repeat on the next file (FindNextFile). Somewhere I have a recursive function that will do it.

Does anybody know of a good VCL?

If nobody answers soon, post here again and I'll post some code.

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
int RecurseDir (char *dir, char *wild, int x)
{
// example: ScanDir( "c:\\", "*.*" );
// Loads the directoryarray

struct ffblk ffblk;
int done;
char buff [512];

strcpy( buff, dir );
strcat( buff, wild );

done = findfirst(buff, &ffblk,
FA_DIREC + FA_SYSTEM
+ FA_HIDDEN + FA_RDONLY + FA_ARCH);

while( !done )
{
if(strcmp(".", ffblk.ff_name) != 0 && strcmp("..", ffblk.ff_name) != 0)
{
if((ffblk.ff_attrib & FA_DIREC) == FA_DIREC)
{
// process directory
strcpy(buff, dir);
strcat(buff, ffblk.ff_name);
strcpy (directoryarray [x], buff);
strcat(buff, "\\");

x++;

x = RecurseDir(buff, wild, x);
}
else
{
//
}
}

done = findnext(&ffblk);
}

return x;
}

int ScanDir (char *dir)
{
// This function scans a directory for all files.
// Loads the filearray

struct ffblk ffblk;
int done;
int x = 0;
char *buff = new char [512];

strcpy(buff, dir);
strcat(buff, "*.*");

done = findfirst(buff, &ffblk, FA_DIREC + FA_SYSTEM + FA_HIDDEN + FA_RDONLY + FA_ARCH);

while(!done)
{
if(strcmp(".", ffblk.ff_name) != 0 && strcmp("..", ffblk.ff_name) != 0)
{
if((ffblk.ff_attrib & FA_DIREC) == FA_DIREC);
else
{
strcpy (filearray [x], ffblk.ff_name);

x++;
}
}

done = findnext(&ffblk);
}

delete buff;

return x;
}


I think I got the beginnings of this from hennep on a previous thread. I just adapted it to my needs and this is what I have at present.

tomcruz.net
 
Is there an easier way to do this using vcl.
 
I don't know of any native VCL components. You can probably find a third party VCL, though.


James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top