Example #1
0
    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
Example #2
0
def delete_last_slash(path):
    if path.endswith(os.sep) or path.endswith("/") or path.endswith("\\"):
        return os.path.dirname(path)
    return path
Example #3
0
 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)