Files
player/conv_code.py

52 lines
1.1 KiB
Python
Raw Permalink Normal View History

2025-06-27 00:32:57 +08:00
import os
# 找到指定后缀的文件
def find_type(path:str,fix:str):
# path = os.getcwd()
# print("path",path)
list=os.listdir(path)
# print("list",list)
file_list=[]
for i in list:
ps=os.path.join(path, i)
if os.path.isdir(ps):
# print("path join",ps)
file_list+=find_type(ps,fix)
else:
if(ps[-len(fix):]==fix):
file_list.append(ps)
# print("file_list", file_list)
return file_list
def conv(file:str):
s=""
try:
2025-07-05 19:05:35 +08:00
with open(file,encoding="utf-8") as f:
2025-06-27 00:32:57 +08:00
s=f.read()
os.remove(file)
2025-07-05 19:05:35 +08:00
with open(file,mode="w+",encoding="gbk") as f:
2025-06-27 00:32:57 +08:00
f.write(s)
except Exception as e:
print("conv failed",file)
def run_conv(path:list):
files=[]
for i in path:
files+=find_type(i,".c")
files+=find_type(i,".h")
print("find files:",len(files))
for i in files:
conv(i)
# 把此文件放到要转码的文件夹下编码转化为utf-8
if __name__ == "__main__":
run_conv(["./"])