【小工具】-按照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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章