Files
2026-09-29 22:41:29 +08:00

54 lines
1.3 KiB
Python

import os
import shutil
import re
# ===== 配置路径 =====
src_dir = r"d:\Users\zzwang\Desktop\Record\未命名混音项目 4\未命名混音项目 4_Recorded" # 原始目录
dst_root = r"E:\esp32_8mic\calibration\data\real" # 目标根目录
# 匹配 _001 ~ _024
pattern = re.compile(r'_(\d{3})')
for filename in os.listdir(src_dir):
src_path = os.path.join(src_dir, filename)
# 跳过文件夹,只处理文件
if not os.path.isfile(src_path):
continue
match = pattern.search(filename)
if not match:
continue
x = int(match.group(1))
# 只处理 _001 ~ _024
if not 1 <= x <= 24:
continue
degree = (x - 1) * 15
# 例如 degree0、degree15、degree30...
dst_dir = os.path.join(dst_root, f"degree{degree}")
# 如果目录不存在则自动创建
os.makedirs(dst_dir, exist_ok=True)
# 去掉角度编号,将轨道 1 / 轨道_1 等格式改为 ch0 ~ ch7
dst_filename = filename[:match.start()] + filename[match.end():]
dst_filename = re.sub(
r'轨道[_\s]+([1-8])(?!\d)',
lambda m: f"ch{int(m.group(1)) - 1}",
dst_filename,
)
dst_path = os.path.join(dst_dir, dst_filename)
shutil.copy2(src_path, dst_path)
print(f"{filename} -> degree{degree}/{dst_filename}")
print("复制完成")