def listdir(self, path): if not self.isdir(path): raise OSError("%s is not a directory" % path) if not path.endswith("/"): path += "/" dirs = [] files = [] for f in self.files: if self.exists(f) and f.startswith(path): remaining = f[len(path) :] if "/" in remaining: dir = remaining[: remaining.index("/")] if not dir in dirs: dirs.append(dir) else: files.append(remaining) return dirs + files
def delete_last_slash(path): if path.endswith(os.sep) or path.endswith("/") or path.endswith("\\"): return os.path.dirname(path) return path
def isdir(self, path): if path in self.files: return False if not path.endswith("/"): path += "/" return any(f.startswith(path) for f in self.files)