[fpc-pascal]directory tree in memory
Michael Van Canneyt
michael.vancanneyt at wisa.be
Mon Oct 15 09:33:52 CEST 2001
On Mon, 15 Oct 2001, Ivan Montes wrote:
> Hi,
>
> Maybe it's a bit off-topic, sorry for any incovenience.
>
> In my library I need to have a repressentation of a directorty tree in memory, to search for files etc.
> I'm using a tList like this :
>
> pMyDirsItem = ^mydirsitem;
> myDirsItem =RECORD
> info :tFileInfo; //name, size, time/date ...
> sub :tList;
> end;
>
> myDirs :tList;
>
> What I do is store the file/directory name and the like in DirsItem.info and if it's a directory "sub" points to another tList with the contents of that directory.
> It works but I would like to know if someone have a better solution for this problem. I'm not very happy with the performance when I have to find a file in it.
Use a TStringList object instead of a Tlist.
Store the name in the string, and in the Object, store
TMyFileObject
Into : TFileInfo;
Sub : TStringList;
end;
If the stringlist object is sorted (Sorted:=True) then any search will use a binary search,
thus speeding up the search quite a lot.
Michael.
More information about the fpc-pascal
mailing list