views:

493

answers:

1

I have an application which behaves as a slideshow for all pictures in a folder. It is written in Borland's C++ Builder (9). It currently uses some borrowed code to throw the filenames into a listbox and save the listbox items as a text file.

I want to update this so that the filenames are stored in a proper database so that I can include extra fields and do proper SQL things with it.

So basically I would be able to work it out if I saw some 'sample' code doing the same thing.

So if anyone knows of any code that does this I would be greatful. It needs to be able to do it on certain file types... not just all the files.

+1  A: 

You basically neeed to write a recursive function with a TDataSet parameter.

(I could not compile my code, so you get it "as is")

void AddFiles(AnsiString path, TDataSet *DataSet)
{
TSearchRec sr;
int f;
    f = FindFirst(path+"\\*.*", faAnyFile, sr);
    while( !f )
    {
     if(sr.Attr & faDirectory)
     {
      if(sr.Name != "."   &&   sr.Name != "..")
      {
       path.sprintf("%s%s%s", path, "\\", sr.Name);
       AddFiles(path, DataSet);
      }
     }
     else
     {
      DataSet->Append();
      DataSet->FieldByName("Name")->Value = sr.Name;
      /* other fields ... */
      DataSet->Post();
     }
     f = FindNext(sr);
    }
    FindClose(sr);
}
Giacomo Degli Esposti
Many thanks for this. I'll try it out when I can which unfortunately is not immediately. I'll let you know the outcome.
MrVimes
I got around to testing this code (albeit without the dataset stuff - just to test getting all files in a dir and it's subdirs) and it doesn't work properly. It messes up the paths...real structureaa\ba\ca\dbecomesaa\ba\b\c(it incorrectly makes a subdir of 'a' into a subdir of 'b'
MrVimes