What i am trying to do is simple tree-search categorizing a master directory. With all sub directories and files beneath it to a database.

I think this is one of the advanced questions and if you have studied CE or CS, you might have an answer to help me.

To save from table number, i constructed only 1 mysql table for directories. The structure is

id - successor - path
1 - 0 - /home
2 - 1 - /home/myuser1
3 - 1 - /home/myuser2
4 - 0 - /etc
5 - 4 - /etc/apache
6 - 0 - /usr
7 - 6 - /usr/local
8 - 7 - /usr/local/bin

and so on. Just to give an example. You can suggest me a new system, i am not sure this is much productive at all.

And there is the problem, scanning all in-depth directories. Simplest (not making the brain work too much) way to do this, writing a 8-9 chained while's like;


Open Directory Level 1 and Read Contents

Foreach Content Item

If directory - write to database (record to an array)

If file - write to database under current directory level id

End foreach

Foreach Array (recorded above) - Open directory level 2 - and read..

.... goes like this till level 8-9.

What i want to know is , if there is a better way to do this?

Open to your discussions, thanks from now!