Probably it is not that much efficient but can't you just use two classes for folders and files, then store the child files and folders inside variables like self._childFiles and self._childFolders which are other File and Folder objects etc... then you can walk through the structure with a simple while loop... but searching will be a little bit involving I think... just an idea...
E.Ozgur Yilmaz Lead Technical Director eoyilmaz.blogspot.com www.ozgurfx.com On Wed, Jun 23, 2010 at 1:58 AM, shawnpatapoff <[email protected]>wrote: > Figured there was some super fast efficient way of doing it. Only buy > I get is if there is a non-directory in the hierarchy...which happens > all the time for me, damn .DS files... > > On Jun 22, 1:21 pm, Chris G <[email protected]> wrote: > > recursion seems a little easier: > > > > root = '/tmp/base' > > import os > > > > def fill(dir): > > subs = os.listdir(dir) > > return dict(zip(subs, (fill(os.path.join(dir,s)) for s in subs))) > > print {root : fill(root)} > > # {'/tmp/base': {'child_1': {'sub_1': {}}, 'child_2': {'sub_2': {}}}} > > > > On Tue, Jun 22, 2010 at 3:39 PM, shawnpatapoff <[email protected]> > wrote: > > > Well, I had some ideas what I wanted to do, but in the end went with > > > this: > > > > > def populateDict(self, pth): > > > lastDir = None > > > vStr = None > > > for root, dirs, files in os.walk(pth): > > > r= root.split('geo_cache')[1][1:] > > > if len(r) > 0: > > > keys = r.split('/') > > > kStr = 'self.cacheDict' > > > for k in keys: > > > kStr += '["' + k + '"]' > > > kStr+='={}' > > > exec(kStr) > > > > > On Jun 22, 12:14 pm, Chris G <[email protected]> wrote: > > >> So are you stuck on the correctness or the efficiency of what you > have? > > > > >> On Tue, Jun 22, 2010 at 1:39 PM, shawnpatapoff < > [email protected]> wrote: > > >> > Hey Chris, > > > > >> > I looked at os.walk and it does work nice. My issue is actually > > >> > capturing the data into a nested dictionary correctly. > > > > >> > On Jun 22, 10:37 am, Chris G <[email protected]> wrote: > > >> >> If it's an existing directory structure, you could just use > os.walk. > > > > >> >> On Tue, Jun 22, 2010 at 1:08 PM, shawnpatapoff < > [email protected]> wrote: > > >> >> > Hey Everyone, > > > > >> >> > I've been trying a decent solution for getting a dictionary > filled > > >> >> > with a specific directory structure. > > > > >> >> > base- > > >> >> > - child_1- > > >> >> > | -sub_1 > > >> >> > | > > >> >> > - child_2- > > >> >> > - sub_2 > > > > >> >> > I would look like: > > >> >> > myDict{base:{child:{sub_1}},{child_2:{sub_2}}} > > > > >> >> > Been messing with various methods, non which seem to be that > > >> >> > efficient. Anyone have any ideas that they would want to share? > > > > >> >> > -s > > > > >> >> > -- > > >> >> >http://groups.google.com/group/python_inside_maya > > > > >> > -- > > >> >http://groups.google.com/group/python_inside_maya > > > > > -- > > >http://groups.google.com/group/python_inside_maya > > > > > > -- > http://groups.google.com/group/python_inside_maya > -- http://groups.google.com/group/python_inside_maya
