Board index » cppbuilder » File search

File search


2005-04-26 07:16:31 AM
cppbuilder29
Hello...
Whats the easyest way to search for files?
I'd like to get for example all *.txt file addresses with names into TMemo:
C:\test.txt
C:\windows\hello.txt
D:\downloads\list.txt
and so on... I hope you got it....
Thanks..
 
 

Re:File search

"Jimbo" < XXXX@XXXXX.COM >wrote in message
Quote
Whats the easyest way to search for files?
Search manually.
Quote
I'd like to get for example all *.txt file addresses with names into
TMemo:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char buffer[108] = {0};
if( GetLogicalDriveStrings(sizeof(buffer), buffer) )
{
char *drive = buffer;
if( *drive != '\0' )
{
UINT old = SetErrorMode(SEM_NOOPENFILEERRORBOX);
do
{
ScanFolder(drive);
drive += 4;
}
while( *drive != '\0' );
SetErrorMode(old);
}
}
}
void __fastcall TForm1::ScanFolder(const AnsiString &Folder)
{
TSearchRec sr;
AnsiString Path = IncludeTrailingBackslash(Folder);
if( FindFile(Path + "*.*", faAnyFile, sr) == 0 )
{
do
{
if( (sr.Name != ".") && (sr.Name != "..") )
{
if( sr.Attr & faDirectory )
ScanFolder(Path + Name);
else if( AnsiSameText(ExtractFileExt(sr.Name), ".txt") )
Memo1->Lines->Add(Path + sr.Name);
}
}
while( FindNext(sr) == 0 );
FindClose(sr);
}
}
Gambit
 

Re:File search

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

if( FindFile(Path + "*.*", faAnyFile, sr) == 0 )
I get error: undefined function 'FindFile' and if I change it to FindFirst
it
I get *.txt files from root of every drive... it doesn't scan subdirs.
I'm not very good @ c++ yet
Jimbo
 

{smallsort}

Re:File search

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

if( sr.Attr & faDirectory )
ScanFolder(Path + Name);

Thanks! I Got it.... ScanFolder(Path + sr.Name); works...