Board index » cppbuilder » About FindFirst/FindNext/FindClose
Shah Lynn
![]() CBuilder Developer |
Shah Lynn
![]() CBuilder Developer |
About FindFirst/FindNext/FindClose2005-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? |
Hans Galema
![]() CBuilder Developer |
2005-02-24 06:26:42 PM
Re:About FindFirst/FindNext/FindClose
Shah Lynn wrote:
QuoteIt seems that FindFirst/FindNext/FindClose can not be used to find directory |
Andrue Cope [TeamB]
![]() CBuilder Developer |
2005-02-24 06:36:37 PM
Re:About FindFirst/FindNext/FindClose
Shah Lynn wrote:
QuoteIt seems that FindFirst/FindNext/FindClose can not be used to find -- Andrue Cope [TeamB] [Bicester, Uk] info.borland.com/newsgroups/guide.html {smallsort} |
Hans Galema
![]() CBuilder Developer |
2005-02-24 10:01:37 PM
Re:About FindFirst/FindNext/FindClose
Shah Lynn wrote:
QuoteI do not know how to deal with it and if any other method to do this job |
Shah Lynn
![]() CBuilder Developer |
2005-02-24 10:06:12 PM
Re:About FindFirst/FindNext/FindClose
"Andrue Cope [TeamB]" < XXXX@XXXXX.COM >????
QuoteShah Lynn wrote: 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. |
Shah Lynn
![]() CBuilder Developer |
2005-02-24 11:06:03 PM
Re:About FindFirst/FindNext/FindClose
"Hans Galema" < XXXX@XXXXX.COM >????
QuoteShah Lynn wrote: 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 --; } |
Hans Galema
![]() CBuilder Developer |
2005-02-24 11:39:06 PM
Re:About FindFirst/FindNext/FindClose
Shah Lynn wrote:
Quoteif (FindFirst("*.cub", iAttributes, sr) == 0) 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. |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2005-02-25 03:14:40 AM
Re:About FindFirst/FindNext/FindClose
"Shah Lynn" < XXXX@XXXXX.COM >wrote in message
Quotevoid __fastcall TForm1::Button1Click(TObject *Sender) 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 |
Shah Lynn
![]() CBuilder Developer |
2005-02-25 03:47:10 PM
Re:About FindFirst/FindNext/FindClose
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >дÈëÓʼþ
Quote
TransversaDir(). Thank you, Hans. |
Shah Lynn
![]() CBuilder Developer |
2005-02-25 03:56:20 PM
Re:About FindFirst/FindNext/FindClose
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >дÈëÓʼþ
Quote
Still, thanks for Hans. At least you teach me the usage of ExtractFileExt ( sr.Name ).LowerCase() and programming style. |