Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just wanted to say how much I have enjoyed these forums. I am a new user and have a lot of elementary questions. I get quick answers with a friendly attitude..."

Geography

Where in the world do Tek-Tips members come from?
801119 (Programmer)
21 Jan 01 16:02
Hey all..!!

I am building a program that will read a CD and then save it's contents to a file..

the problem is to search all subdirs! Is there any easy way to do this?

I am using findfirst(..)

!thanks..!!


Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society

2ffat (Programmer)
22 Jan 01 7:19
I'm not aware of any "easy" way to do this. I used this method to create a similar function. I did read a 4-part article in C++ Builder Developer's Journal in which the author (Mark G. Wiseman) created some classes to list files. His classes included include or exclude properties. Their web site is www.reisdorph.com and the article was entitled "Finding Files." You may have to be a subscriber, I don't know.

If that is not to your liking, post some of your code here and we'll see what we can do.

James P. Cottingham
www.ivcusa.com

801119 (Programmer)
25 Jan 01 11:45
Ok....So there is no easy way to do this!!

I can only search one dir!! And when there is more then one folder...trouble!!

// This is the code I use to search current dir for additional folders!! One other problem is, that with the use of *. it will also list all files with no extension

//--------- note that I did not write this code my self most was found in the help files that came with BCB3 standard
#include <dir.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 int done;
 struct ffblk ffblk;
 chdir("\\"); // To make sure we read from root dir
 done = findfirst("*.",&ffblk,faDirectory);
 while (!done)
    {
    // only store directories, ignoring "." and ".."
    char *impline;
    impline = ffblk.ff_name;
     if(impline[0]!='.') // another problem is that full pathname is not listed!!!
       Memo1->Lines->Add(impline);
     done = findnext(&ffblk);
    }
}
//---------

A simple folder structure I am trying to use to find a solution!! It's gives more pain then help! {=P

   C:\
    |-Windows-|-System32-|-Folder
    |         |-Command-|Folder
    |
    |-Program files-|-ACDSee
    |               nternet Explorer-|-PLUGINS
    |-Backup-|-System-|-Folder 1
    |        |        |-Folder 2
    |        |        |-Folder 3


Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society

2ffat (Programmer)
25 Jan 01 12:57
There might be any easy way if you want to display on screen the directories. Look at the VCL components TDriveComboBox, TDirectoryListBox, and TFilterCombo.

What you are doing above is correct so far. However, you need to use the full wildcard "*.*" and then call a Windows API named WIN32_FIND_DATA. When the  FILE_ATTRIBUTE_DIRECTORY bit is set, then you have a directory.

I would suggest the book Borland C++ Builder: The Definitve Problem-Solver by Miano, Cabanski, and Howe. Howe has a web site, www.bcbdev.com that has some of the books examples on site. Also check out the links at his site.

Failing that, e-mail me at cottingham@msinets.com and I can send you some examples.

James P. Cottingham
www.ivcusa.com

801119 (Programmer)
27 Jan 01 13:08
I do not wish to show the folder(s) on screen... I only want to search a folder(inc. subdirs) for files(*.*) and then save a list of folder Contents to a file, a friend of my brother wants such a program to read a CD!

If I am to use the API WIN32_FIND_DATA I need to know how it works!! How to use it!!
I would appreciate if you could help me with that!


Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society

2ffat (Programmer)
31 Jan 01 7:31
I haven't forgotten about you. I am putting together an example but I haven't had much spare time. Please stand by.

James P. Cottingham
www.ivcusa.com

2ffat (Programmer)
2 Feb 01 12:05
Sorry this has taken me so long. I've been very busy, as usual, so I haven't had much time to research this out. I'm going to show you a part of a program that I wrote. Then I'm going to add some elements that I haven't test yet. I'm doing this on my lunch hour so I don't have much time. I was going to do two programs. One the way I'm showing you and the other using WIN32_FIND_DATA but I don't have time. So here goes:

struct ffblk ff;    // prototype in dir.h

int done, direct, subdirect;

// get directories in question
done = findfirst("C:\\*.", &ff, FA_DIREC);
while (!done)
     {
          // don't include current directory or root directory
          direct = strcmp(ff.ff_name, ".");
          subdirect = strcmp(ff.ff_name, "..");

          if (direct != 0 && subdirect != 0)
          {
    cout << "Found File: " << ff.ff_name << endl;
              AnsiString SFile = ff.ff_name; // I'm not certain if this works
              AnsiString SPath = ExtractFilePath(SFile); // If the above work, this will
          }
    
     // get next directoy
     done = findnext(&ff);
}


AnsiString and ExtractFilePath are automatically included with vcl.h so there is nothing to include manually. ExtractFilePath is part of the Sysutils unit and is poorly documented but has a lot of useful functions. AnsiString is well documented.

The only thing I can't remember right know is if you can set SFile to ff.ff_name directly or if you have to convert one or the other first, maybe with .c_str.

The other thing I notice is that you used faDirectory in findfirst. I used FA_DIRECT.

Good luck. My lunch time is over.

James P. Cottingham
www.ivcusa.com

801119 (Programmer)
4 Feb 01 17:12
Thanks a lot!

You know what, I actually made an application that searches subdirectories! :) Neat or what?
Though the code is somewhat stirred up, it actually works.
Perhaps you will find a flaw or two(hundred =); and if you do find something that can be improved, please let me know!
Here is the main search code: (It uses A TListBox and a TRichEdit and a TButton)
AnsiString curr_path; // the path to search in
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 RichEdit1->Lines->Clear(); // clear TRichEdit
 ListBox1->Items->Clear(); // clear TListBox
 int direct, subdirect;
 ListBox1->Items->Add(“C:”); // Add root path, the first path we will search
 while(ListBox1->Items->Count>0) // While we have a folder to search
    { // get new path to search,
     curr_path = ListBox1->Items->Strings[0]+"\\";
     done = findfirst((AnsiString(curr_path)+"*.*").c_str(), &ffblk,faDirectory);
     while (!done)
        { // compare two strings
         direct = strcmp(ffblk.ff_name, ".");
         subdirect = strcmp(ffblk.ff_name, "..");
         if (direct != 0 && subdirect != 0 && ffblk.ff_attrib==FA_DIREC)
                  // add path to TListBox
            ListBox1->Items->Insert(1, (AnsiString(curr_path) + AnsiString(ffblk.ff_name)) );
         if(direct != 0 && subdirect != 0 && ffblk.ff_attrib!=FA_DIREC)
                  // add path + filename to TRichEdit
             RichEdit1->Lines->Add( curr_path+ffblk.ff_name );
         done = findnext(&ffblk); // Find next file or folder
        }
     ListBox1->Items->Delete(0); // delete previously searched folder from TListBox
    }
}


Thanks for helping and inspiring!
   Martin

P.S I appreciate you taking time to help me whenever needed! It has been very helpful! D.S


Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society

2ffat (Programmer)
5 Feb 01 7:11
Your welcome. Glad I could be of some (little?) help. Why not make a FAQ in this thread with your code? you may have to make it a little more generic but I suspect more people will be looking for something similar.

James P. Cottingham
www.ivcusa.com

801119 (Programmer)
5 Feb 01 14:26
How do I make a FAQ out of this thread?!
I would more then gladly supply others with it when modified a bit and more efficient (of course)!


Martin G Broman
mgb_svea@thevortex.com

DWS - Alpha Whitin Dead Wolf Society

2ffat (Programmer)
6 Feb 01 6:48
What I did was create the FAQ in an editor. Then went to this forum, opened up the FAQ, created a new thread, and pasted the FAQ from the editor to the forum's FAQ.

James P. Cottingham
www.ivcusa.com

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close