On Feb 17, 9:08 pm, Christian Heimes <li...@cheimes.de> wrote: > Thomas Allen wrote: > > If you'd read the messages in this thread you'd understand why I'm not > > using os.walk(): I'm not using it because I need my code to be aware > > of the current recursion depth so that the correct number of "../" are > > substituted in. > > I'm well aware of your messages and your requirements. However you > didn't either read or understand what I was trying to tell you. You > don't need to know the recursion depths in order to find the correct > number of "../". > > base = os.path.normpath(base) > baselevel = root.count(os.sep) > > for root, dirs, files in os.walk(base): > level = root.count(os.sep) - baselevel > offset = level * "../" > ... > > See? > > Christian
Very clever (and now seemingly obvious)! That certainly is one way to measure directory depth; I hadn't thought of counting the separator. Sorry that I misunderstood what you meant there. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list