PDA

View Full Version : Finding all files in a folder



Crisp_N_Dry
08-05-2003, 07:36 PM
I'm working on my map editor at the moment and I need the editor to load a list of all files in the objects directory (say 'C:\Editor\Objects') but can't for the life of me work out how to do it. I don't want to use a component, I need pure code (libraries are fine). There must be an easier way of doing this. It seems so simple yet I don't know how. Am I missing something glaringly obvious or what? Can anyone help?

Harry Hunt
08-05-2003, 08:27 PM
var
Rec: TSearchRec;
SearchResult: Integer;
begin
SearchResult := FindFirst('C:\MyObjects\*.obj', faAnyFile, Rec);
while SearchResult = 0 do
begin
LoadFile('C:\MyObjects\' + Rec.Name); // Do something with the file we've just found
SearchResult := FindNext(Rec);
end;
end;

Alimonster
12-05-2003, 08:52 PM
Chuck a FindClose in there too...

Harry Hunt
12-05-2003, 09:07 PM
Ooops! Totally forgot about that.