[脚本无敌2]python获取cocos 2dx项目文件列表

在将cocos 2dx代码移植到android jni时会使用到,有需要的拿走就好,free~~

# -*- coding: gbk -*-
# function:获取cocos 2dx项目的cpp文件列表,在移植到android时使用
# input:项目路径
# output:txt格式的cpp文件列表
import time, os, sys
import glob

print 'input project path:'
file_path_input = raw_input()
# file_path_input = 'D:\cocos2d-x-3.3rc0\projects\projectname'  # 工程根路径/文件路径
print file_path_input

file_type = '*.cpp'  # 文件格式

file_path = file_path_input + '\\Classes\\'
cpp_list = glob.glob(file_path + file_type)

cpp_list_len = len(cpp_list)
if cpp_list_len == 0:
    print '\n--no file--'
    sys.exit()
cpp_filename = 'cpp_list.txt'
f = open(cpp_filename, 'wt')
ind = 0
for item in cpp_list:
    item = item.replace(file_path, '')
    print item
    ind = ind + 1
    if ind < cpp_list_len:
        item = '../../Classes/' + item + ' \\'
    else:
        item = '../../Classes/' + item
    f.write(item)
    f.write('\n')
f.close()

# 打开列表文件
os.system("explorer.exe %s" % cpp_filename)

android_project_path = file_path_input + '\proj.android\jni\Android.mk'
print android_project_path

# 打开android jni文件夹
os.system("explorer.exe %s" % android_project_path)  

  

posted @ 2014-12-28 12:13  yemuzi  阅读(261)  评论(0编辑  收藏  举报