I'm seeking advice on elegant designs for representing a file directory without symlinks in Python where I can query the relationships in terms of "belongs to" (e.g. G is a subdirectory of /A/B/C). My current thinking goes in this direction:
Given a root path I os.path.walk() it top down. Two classes represent the node types I'm interested in and I keep track of parent child relationships.
class ADir(object):
def __init_(self, name, parent=None):
self.name = name
self.parent = parent
self.children = []
def add_child(self, id):
self.children.append(id)
class AFile(object):
def __init_(self, name, parent=None):
self.name = name
self.parent = parent
I would have to re-implement checks for existing directories, functions which give me the position of a directory/file etc. It all starts to feel very much like a reimplementation of existing, general Tree algorithms.
Trawling trough StackExchange, Google, etc. yields a host of various approaches. None which I found seemed to make use of the natural boundaries given a directory structure.
Any thoughts and pointers to discussions, blog entries and code are appreciated.