我不认为这个任务是一个“轮子”(可以这么说)。但这可以通过您提到的工具轻松实现:
import osimport jsondef path_to_dict(path): d = {'name': os.path.basename(path)} if os.path.isdir(path): d['type'] = "directory" d['children'] = [path_to_dict(os.path.join(path,x)) for x in os.listdir(path)] else: d['type'] = "file" return dprint json.dumps(path_to_dict('.'))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)