Final question for the night. And apologies for the complete noobness of this.
I have, with help from stackoverflow and google achieved the following...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ADOCommand1->CommandText = "drop table pictures purge";
ADOCommand1->Execute();
ADOCommand1->CommandText = "create table pictures(id autoincrement, filename TEXT(255), notes text(255), category text(20), rank int, filedate datetime,constraint table1_PK primary key(id));";
ADOCommand1->Execute();
AddFiles(Edit1->Text);
}
//---------------------------------------------------------------------------
int AddFiles(AnsiString path, int count)
{
TSearchRec sr;
int f,count2=0;
f = FindFirst(path+"\\*.*", faAnyFile, sr);
while( !f )
{
if(sr.Attr & faDirectory)
{
if(sr.Name != "." && sr.Name != "..")
{
AnsiString subpath;
subpath.sprintf("%s%s%s", path, "\\", sr.Name);
count = AddFiles(subpath,count);
}
}
else
{
Form1->ADOCommand1->CommandText = "Insert into pictures (filename) values ('" + StringReplace(path + "\\" + sr.Name, "'", "''", TReplaceFlags()<<rfReplaceAll) + "')";
Form1->ADOCommand1->Execute();
++count;
++count2;
if (count2 > 100)
{
count2 = 0;
Form1->Caption = "Added " + IntToStr(count)+ " Files.";
Application->ProcessMessages();
}
}
f = FindNext(sr);
}
FindClose(sr);
return count;
}
It is basically traversing a given directory and its subdirs, and adding each file (with path) to an MS Access database.
(I am the only user so I don't care much about security)
With a large number of files this code is horribly slow. Can anyone describe a better way to do what the code is doing, (hopefully without making your answer too complicated. I'm a noob to this remember)