dictionary of folders and subfolders

后端 未结 3 975
被撕碎了的回忆
被撕碎了的回忆 2020-12-12 05:38

I need to make function, which will return for a given folder, a Dictionary, which describes its content. Keys let be the names of the subfolders and files, key value repres

3条回答
  •  爱一瞬间的悲伤
    2020-12-12 06:04

    def f(path):
        if os.path.isdir(path):
            d = {}
            for name in os.listdir(path):
                d[name] = f(os.path.join(path, name))
        else:
            d = os.path.getsize(path)
        return d
    

提交回复
热议问题