code: def sorted(self, wantdirs=False):
          
  
          def add_dir(dirs, d):
              dirs.add(d)
              logger.debug('add_dir added %s', d)
              if d != self.base:
                  parent, _ = os.path.split(d)
                  assert parent not in ('', '/')
                  add_dir(dirs, parent)
  
          result = set(self.files)    # make a copy!
          if wantdirs:
              dirs = set()
              for f in result:
                  add_dir(dirs, os.path.dirname(f))
              result |= dirs
          return [os.path.join(*path_tuple) for path_tuple in
                  sorted(os.path.split(path) for path in result)]
docs: Return sorted files in directory order