Board index » cppbuilder » About FindFirst/FindNext/FindClose

About FindFirst/FindNext/FindClose


2005-02-24 06:26:14 PM
cppbuilder63
It seems that FindFirst/FindNext/FindClose can not be used to find directory
on CD-rom in CD Driver, instead, it works for HDD. What can I do for this
problem?
 
 

Re:About FindFirst/FindNext/FindClose

Shah Lynn wrote:
Quote
It seems that FindFirst/FindNext/FindClose can not be used to find directory
on CD-rom in CD Driver, instead, it works for HDD. What can I do for this
problem?
Of course it can examine a cd. What makes to think different ?
Hans.
 

Re:About FindFirst/FindNext/FindClose

Shah Lynn wrote:
Quote
It seems that FindFirst/FindNext/FindClose can not be used to find
directory on CD-rom in CD Driver, instead, it works for HDD. What can
I do for this problem?
There should be no difference. What do you mean by "can not be used to
find directory on CD-rom in CD Driver"?
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

{smallsort}

Re:About FindFirst/FindNext/FindClose

Shah Lynn wrote:
Quote
I do not know how to deal with it and if any other method to do this job
exists.
Please show your code.
Hans.
 

Re:About FindFirst/FindNext/FindClose

"Andrue Cope [TeamB]" < XXXX@XXXXX.COM >????
Quote
Shah Lynn wrote:

>It seems that FindFirst/FindNext/FindClose can not be used to find
>directory on CD-rom in CD Driver, instead, it works for HDD. What can
>I do for this problem?

There should be no difference. What do you mean by "can not be used to
find directory on CD-rom in CD Driver"?

--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
Yes, that's wiered.
To be more specific, I wrote piece of code to transversa directory to find
all file with specific extension,say ".abc". It works quite well on HDD, but
with CD-ROM in CD driver, it can only discover this kind of file within the
root directory.Moreover, while running on HDD,the HDD LED is
lighted,meanwhile,while running on CD ROM, the CD driver seems no operation.
I do not know how to deal with it and if any other method to do this job
exists.
 

Re:About FindFirst/FindNext/FindClose

"Hans Galema" < XXXX@XXXXX.COM >????
Quote
Shah Lynn wrote:

>I do not know how to deal with it and if any other method to do this job
>exists.

Please show your code.

Hans.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
using namespace std;
FileNumber = 0;
DirDepth = 0;
DirDepthTemp = 0;
StatOut();
AnsiString Dir = "\\";
if (SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate <<
sdPerformCreate << sdPrompt, SELDIRHELP))
Label1->Caption = Dir;
TransversaDir(Dir);
StatOut();
}
//--------------------------------------------------------------------------
-
void TForm1::TransversaDir(AnsiString ParentDir)
{
//TODO: Add your source code here
TSearchRec sr;
int iAttributes;
DirDepthTemp ++;
if( DirDepth < DirDepthTemp ) DirDepth = DirDepthTemp;
/*
Search CUB file
*/
SetCurrentDir( ParentDir );
iAttributes = faAnyFile;
if (FindFirst("*.cub", iAttributes, sr) == 0)
{
do
{
if ((sr.Attr & iAttributes) == sr.Attr)
{
FileNumber++;
}
} while (FindNext(sr) == 0);
FindClose(sr);
}
/*
Search SubDir
*/
iAttributes = faDirectory;
if (FindFirst("*.*", iAttributes, sr) == 0)
{
do
{
if((!strstr(sr.Name.c_str(),"."))&&((sr.Attr & iAttributes) ==
sr.Attr))
{
TransversaDir( ParentDir + "\\" + sr.Name );
}
} while (FindNext(sr) == 0);
FindClose(sr);
}
DirDepthTemp --;
}
 

Re:About FindFirst/FindNext/FindClose

Shah Lynn wrote:
Quote
if (FindFirst("*.cub", iAttributes, sr) == 0)
if (FindFirst("*.*", iAttributes, sr) == 0)
You traverse every directory twice. That is not a good approach.
But the problem is that FindFirst is not very good in finding
files with the specified extension.
So you better remove the first FindFirst()/Findnext() loop completely.
In the second loop check if it is a directory and ten recurse and
otherwise see if the extension matches.
if ( ExtractFileExt ( sr.Name ).LowerCase() == ".cub" )
++;
Hans.
 

Re:About FindFirst/FindNext/FindClose

"Shah Lynn" < XXXX@XXXXX.COM >wrote in message
Quote
void __fastcall TForm1::Button1Click(TObject *Sender)
<snip>
void TForm1::TransversaDir(AnsiString ParentDir)
<snip>
Use this code instead:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
FileNumber = 0;
StatOut();
AnsiString Dir = "C:\\";
if( SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate <<
sdPerformCreate << sdPrompt, SELDIRHELP) )
{
Label1->Caption = Dir;
TransversaDir(Dir);
}
StatOut();
}
void TForm1::TransversaDir(const AnsiString &ParentDir)
{
TSearchRec sr;
AnsiString Folder = IncludeTrailingBackslash(ParentDir);
if( FindFirst(Folder + "*.*", faAnyFile, sr) == 0 )
{
do
{
if( (sr.Name != ".") && (sr.Name != "..") )
{
if( sr.Attr & faDirectory )
TransversaDir(Folder + sr.Name);
else
{
if( AnsiSameText(ExtractFileExt(sr.Name), ".cub") )
{
// do something with sr.Name as needed...
++FileNumber;
}
}
}
}
while( FindNext(sr) == 0 );
FindClose(sr);
}
}
Gambit
 

Re:About FindFirst/FindNext/FindClose

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >дʼ
Quote

"Shah Lynn" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>void __fastcall TForm1::Button1Click(TObject *Sender)
<snip>
>void TForm1::TransversaDir(AnsiString ParentDir)
<snip>

Use this code instead:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
FileNumber = 0;
StatOut();

AnsiString Dir = "C:\\";
if( SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate <<
sdPerformCreate << sdPrompt, SELDIRHELP) )
{
Label1->Caption = Dir;
TransversaDir(Dir);
}

StatOut();
}

void TForm1::TransversaDir(const AnsiString &ParentDir)
{
TSearchRec sr;

AnsiString Folder = IncludeTrailingBackslash(ParentDir);

if( FindFirst(Folder + "*.*", faAnyFile, sr) == 0 )
{
do
{
if( (sr.Name != ".") && (sr.Name != "..") )
{
if( sr.Attr & faDirectory )
TransversaDir(Folder + sr.Name);
else
{
if( AnsiSameText(ExtractFileExt(sr.Name),
".cub") )
{
// do something with sr.Name as needed...
++FileNumber;
}
}
}
}
while( FindNext(sr) == 0 );
FindClose(sr);
}
}


Gambit


Nothing is more important for a newbie than to make it happen.
Yes, it does work, after I change the parameter type of function
TransversaDir().
Thank you, Hans.
 

Re:About FindFirst/FindNext/FindClose

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >дʼ
Quote

"Shah Lynn" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>void __fastcall TForm1::Button1Click(TObject *Sender)
<snip>
>void TForm1::TransversaDir(AnsiString ParentDir)
<snip>

Use this code instead:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
FileNumber = 0;
StatOut();

AnsiString Dir = "C:\\";
if( SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate <<
sdPerformCreate << sdPrompt, SELDIRHELP) )
{
Label1->Caption = Dir;
TransversaDir(Dir);
}

StatOut();
}

void TForm1::TransversaDir(const AnsiString &ParentDir)
{
TSearchRec sr;

AnsiString Folder = IncludeTrailingBackslash(ParentDir);

if( FindFirst(Folder + "*.*", faAnyFile, sr) == 0 )
{
do
{
if( (sr.Name != ".") && (sr.Name != "..") )
{
if( sr.Attr & faDirectory )
TransversaDir(Folder + sr.Name);
else
{
if( AnsiSameText(ExtractFileExt(sr.Name),
".cub") )
{
// do something with sr.Name as needed...
++FileNumber;
}
}
}
}
while( FindNext(sr) == 0 );
FindClose(sr);
}
}


Gambit


Sorry for mis-reply. I'd appreciate the help from Remy. Your code solve the
problem. I think that my mistake is at path string operation.
Still, thanks for Hans. At least you teach me the usage of ExtractFileExt
( sr.Name ).LowerCase() and programming style.