차트 종류가 분산형일 경우 예외처리 [2-53~58]

This commit is contained in:
2025-10-29 16:19:12 +09:00
parent d97502ff5c
commit 58d329d816
131 changed files with 1435 additions and 45842 deletions

54
01_copy_files_answer.py Normal file
View File

@@ -0,0 +1,54 @@
import os
import shutil
from pathlib import Path
import re
# ===== 사용자 설정 =====
source_dir = r"D:\project\HWP\HWP-Scoring\회차별채점자료\2510"
exam_round = "2510" # 회차명
exam_code = "DIW" # 코드명
# =======================
def get_exam_type(filename: str):
"""
파일명에서 확장자 앞의 마지막 알파벳을 추출 (예: 국어A.hwpx → A)
"""
match = re.search(r"([A-Za-z])\.hwpx$", filename)
return match.group(1).upper() if match else None
def copy_exam_files():
src = Path(source_dir)
if not src.exists():
print(f"경로를 찾을 수 없습니다: {src}")
return
base_dest = Path(".") / "input" / exam_round
copied = 0
for path in src.rglob("*"):
if path.is_file() and path.suffix.lower() == ".hwpx":
exam_type = get_exam_type(path.name)
if not exam_type:
continue # 마지막 문자가 알파벳이 아니면 건너뜀
dest_dir = base_dest / exam_type / exam_code
dest_dir.mkdir(parents=True, exist_ok=True)
dest_path = dest_dir / path.name
# 같은 이름의 파일이 있을 경우 숫자 붙이기
counter = 1
while dest_path.exists():
dest_path = dest_dir / f"{path.stem}_{counter}{path.suffix}"
counter += 1
shutil.copy2(path, dest_path)
print(f"복사 완료: {path}{dest_path}")
copied += 1
print(f"\n{copied}개 파일 복사 완료.")
if __name__ == "__main__":
copy_exam_files()