Building a directory tree into the database


Does anyone can give me some pointers on building a directory tree. I
want to map a directory of folders and files into a database. I am not
sure how to do this dynamically. I think acts_as_tree could help me do
this. Any ideas?



I manage a database to map directories too …
I use the plugin better_nested_set :
You can mange roots and children easily with this.
When you get, for example, a directory containing others directories
and files,
you can add the first directory as root and subdirectories and files
as children of root… with “child.move_to_child_of root”
When you want to get children for the root directory with your model :
“root.children” or “child.children” etc …
And to get the parent directory : “chid.parent” or “child.ancestors”
etc …
You just have to parse the directory tree with Dir.entries or anything
else and add the results to the database using your model containing
acts_as_nested_set and saving each entries using move_to_child_of
method if it’s needed.