import os
# 指定要遍历的目录路径
directory_path = 'E:\\web\\danzi\\xxx\\uniapp\\pages' # 请替换为实际的目录路径
# 遍历目录及其子目录中的所有文件
for root, dirs, files in os.walk(directory_path):
for file in files:
# 检查文件是否以.vue结尾
if file.endswith('.vue'):
# 拼接完整的文件路径
full_path = os.path.join(root, file)
# 去除.vue后缀,只保留文件名
file_name_without_extension = os.path.splitext(file)[0]
# 构建新的路径格式
new_path = f"pages/{os.path.relpath(root, directory_path)}/{file_name_without_extension}"
# 生成符合要求的格式文本
json_text = f'{{"path": "{new_path}", "style": {{"navigationBarTitleText": ""}}}},'
# 打印或写入文件
print(json_text) # 打印结果
# 如果需要写入文件,请取消注释下一行
# with open('output.txt', 'a') as f: # 打开文件准备追加内容
# f.write(json_text + '\n') # 写入文件并换行
发表评论 取消回复