WXMC/bat/export_tables.py
2024-12-04 16:18:46 +08:00

39 lines
1.6 KiB
Python

import os
import shutil
import glob
exporter_path = '../tool/ExcelCompiler/ExcelCompiler.dll'
def find_and_export_excels(source_dir, target_dir):
# Make sure target directory exists
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# Find all Excel files (.xlsx and .xls)
excel_files = glob.glob(os.path.join(source_dir, '**', '*.xlsx'), recursive=True)
excel_files += glob.glob(os.path.join(source_dir, '**', '*.xls'), recursive=True)
# Process each Excel file
for excel_file in excel_files:
# Get the base name of the file (without directories)
base_name = os.path.basename(excel_file)
if base_name.startswith('~'):
continue
# Remove the old extension and add the new .bytes extension
new_name = os.path.splitext(base_name)[0] + '.bytes'
# Create the full path for the new file in the target directory
target_path = os.path.join(target_dir, new_name)
# Copy the file to the new location
#shutil.copy2(excel_file, target_path)
os.system('dotnet {exporter} -i {old_path} -o {new_path}'.format(exporter = exporter_path, old_path = excel_file, new_path = target_path))
print(f"Exported: {excel_file} -> {target_path}")
if __name__ == "__main__":
#source_directory = input("Enter the source directory path: ")
#target_directory = input("Enter the target directory path: ")
source_directory = '../proj/unity/tables'
target_directory = '../proj/unity/Assets/Config/Tables'
find_and_export_excels(source_directory, target_directory)