Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active February 14, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/110036747e572dde2a03384b90d4ac7c to your computer and use it in GitHub Desktop.
Save baobao/110036747e572dde2a03384b90d4ac7c to your computer and use it in GitHub Desktop.
# -*- coding: UTF-8 -*-
import os.path
import sys
import xml.etree.ElementTree as ET
# 書き出し相対ディレクトリパス
# 適宜設定する
BaseRelativePath='export/'
args = sys.argv
# tpsファイルチェック
tpsPath = args[1]
if not tpsPath or tpsPath.find('.tps') < 0:
print('ERROR : 「.tps」ではないので、処理を中断します')
sys.exit()
# xmlファイルの読み込み
tree = ET.parse(tpsPath)
root = tree.getroot()
# 拡張子を抜いたファイル名を取得する
path,ext = os.path.splitext(tpsPath)
temp = path.split("/")
noExFileName = temp[len(temp)-1]
# 書き出しパスの設定ノードの取得
exportNode=root.find('struct/map/struct/filename')
# 新しい書き出しパスで上書き
exportNode.text = BaseRelativePath + noExFileName + '.tpsheet';
# .tpsを上書き保存します
tree.write(tpsPath, 'utf-8', True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment