UGCProjects/Tool/copy_lua_files.py
2025-01-04 23:00:19 +08:00

57 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os.path
import re
import utils
def test_copy(source, dest: str):
sourceFiles = utils.listFiles(source, 'lua')
for i in sourceFiles:
print(i)
content = utils.load_file(filename=i, encode='utf-8')
# 创建文件
filename = i.replace(source, dest)
utils.file_exist(filename)
with open(file=filename, mode="w", encoding='utf-8') as f:
f.write(content)
f.close()
# 将代码中所有的 :fun 替换成 fun
def test_remove_simple(source: str):
sourceFiles = utils.listFiles(source, 'lua')
for i in sourceFiles:
with open(i, mode='r', encoding='utf-8') as f:
content: str = f.read()
f.close()
# 检查前面是否含有 (
arr = content.split('\n')
conts = []
for c in arr:
conts.append(utils.replace_first_occurrence(c, ':fun(', ' fun('))
content = '\n'.join(conts)
with open(i, mode='w', encoding='utf-8') as f:
f.write(content)
f.close()
def test2(foldername: str = None):
if foldername is None:
foldername = '..\\'
else:
foldername = '..\\' + foldername + '\\Script'
utils.add_type(foldername)
def test1():
test_remove_simple(r'..\..\Content\LuaHelper')
if __name__ == '__main__':
# test_copy('ProjectTemp', 'Test_Island')
# os.system("rmdir.bat")
# test2('AthleticMasters')
test1()
# utils.removeFiles('..\\Saved\\Logs\\Test_Island')
pass