【小工具】-按照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)