54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
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() |