I had a problem like this awhile ago.
Here's my solution:
It was kind of nice to be able to do this:
And not clutter the program up with a bunch of tree handling stuff.
lookup_directory_ancestor_path(id) LIKE 'Blah/%';
I was going to go with flat files at first, but decided I wanted relational after thinking about some of the other aspects (integrity checks).
You can also create database-side indexes, but in practice, I haven't needed them. (I just created an index, then dropped it, to see if it'd actually work.)