Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-10

directory tree in memory

11 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ivan Montes

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.

thanks, Ivan

Gabor DEAK JAHN
to Ivan Montes

At 10/15/01 01:29 AM, you wrote:

Ivan,

Show quoted text 5 lines
pMyDirsItem = ^mydirsitem; myDirsItem =RECORD info :tFileInfo; //name, size, time/date ... sub :tList; end;

A slight modification would yield a more general solution:

type
   PDirNode = ^TDirNode;
   TDirNode = record
     info : ...
     Next, Sub : PDirNode;
var
   Root : PDirNode;

For each node, you can store the file information bits, as you described. If it is a directory, the Sub will point to the node of the subdirectory, for a simple file Sub = nil. In addition, Next points to the next node (directory or file residing in the same directory), for the last node in the list, Next = nil;

To go through the whole structure (to find a file or for any other reason), you have to walk this tree--the actual order might differ but I guess post-order would be the most suited for the usual tasks you can do with file system structures. Thus, you first process the info field (eg. when looking for a file, compare the name or attributes to the one you are looking for). Then, if Sub nil, you proceed to the node pointed by Sub recursively. When you return, if Next nil, you proceed to the node pointed by it. If Next = nil, you return back to the caller. Basically:

Walk (p : PDirNode);
begin
   repeat
     ... p^.info ...
     if Sub  nil then Walk (Sub);
     p := p^.Next;
   until p = nil;
end;

Regards,

   Gabor DEAK JAHN

------------------------------------------------------------------- Gabor DEAK JAHN -- Budapest, Hungary.
WWW: www.tramontana.co.hu
E-mail:

Michael Van Canneyt
to Ivan Montes: Maybe it's a bit off-topic, sorry for any incovenience. In my library I need to have a…
Ivan Montes wrote 17 lines
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.

Marco van de Voort
to Michael Van Canneyt
Show quoted text 17 lines
> 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.

I still have some directory traversal routines. Afaik they are even in xtdfpc on my page (see contrib page). Unit is called odirtree or so.

Lee, John

Or for wincvs... http://www.wincvs.org/ J

Earlier message 22 lines
-----Original Message----- From: Adam Naumowicz Sent: Monday, October 15, 2001 03:31 To: Subject: Re: [fpc-pascal]cvs where download for win? On Mon, 15 Oct 2001, Zbynek Grygar wrote: > Please send me url where i can fin CVS for windows http://www.cvshome.org Regards, Adam Naumowicz -------------------------------------- WWW: http://math.uwb.edu.pl/~adamn/ -------------------------------------- This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
Ivan Montes
to Michael Van Canneyt: Use a TStringList object instead of a Tlist. Store the name in the string, and in the…
Show quoted text 9 lines
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.

fist thanks to everybody who've answered me,

And now following Michael's advice I'm using tStringList but I found that the property CaseSensitive is not declared in the class. I downloaded the FCL source some days ago so maybe it's fixed already.

bye, Ivan

Michael Van Canneyt
to Ivan Montes
Ivan Montes wrote 17 lines
> 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. > fist thanks to everybody who've answered me, And now following Michael's advice I'm using tStringList but I found that the property CaseSensitive is not declared in the class.

There is no such property. Where did you find that ?

Michael.

Ivan Montes
to Michael Van Canneyt
Show quoted text 5 lines
>tStringList but I found that >the property CaseSensitive is not declared in the class. There is no such property. Where did you find that ?

In the Delphi6 help files. I looked for tStringList and in the properties section says that CaseSensitive is a boolean value that if set to true the "find" method will use CompareAnsiStr instead of CompareAnsiText. Maybe is something new in Delphi6, but I think is usefull and simple to implement.

bye, Ivan