按照xmind层结构转成文件夹形式

如下图所示,将如下的xmind层级结构转换为具体的文件夹结构:
【小工具】-按照xmind层结构转成文件夹形式
然后将上面的层级结构转成如下形式:
【小工具】-按照xmind层结构转成文件夹形式

详细代码如下:

#coding:utf-8
from xmindparser import xmind_to_dict
import os
xmind_file = "d:/a.xmind"
out = xmind_to_dict(xmind_file)
xmind_struct = out[0]
xmind_topic =[]
working_dir = "D:/"
def mkdir_dict(path):
    if not os.path.exists(path):
        os.mkdir(path)
def list_all_dict(dict_a,path):
    if isinstance(dict_a, dict):  # 使用isinstance检测数据类型
        if dict_a.has_key('title'):
            title = dict_a['title']
            print" %s" % (os.path.join(path,title))
            mkdir_dict(os.path.join(path,title))
            # q.put(os.path.join(path,title))
            if dict_a.has_key('topics'):
                sub_dict = dict_a['topics']
                for i in sub_dict:
                    list_all_dict(i,os.path.join(path,title))
if __name__ =="__main__":
    if xmind_struct.has_key('topic'):
        xmind_topic = xmind_struct['topic']
        list_all_dict(xmind_topic,working_dir)

相关文章:

  • 2021-08-10
  • 2021-08-05
  • 2021-04-21
  • 2021-08-14
  • 2021-08-12
  • 2021-09-24
  • 2021-04-01
猜你喜欢
  • 2021-12-01
  • 2021-08-23
  • 2021-05-30
  • 2021-05-07
  • 2021-11-29
  • 2021-12-17
相关资源
相似解决方案