2603회 채점완료
This commit is contained in:
@@ -1,57 +1,49 @@
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
import re
|
||||
import glob
|
||||
|
||||
# 회차별채점자료/회차명 폴더안 정답 파일만 복사하는 스크립트
|
||||
# ── 설정 ────────────────────────────────────────────────────────────────
|
||||
exam_round = "2603" # 회차명
|
||||
exam_code = "DIW" # 코드명
|
||||
|
||||
# ===== 사용자 설정 =====
|
||||
source_dir = r"D:\project\HWP\HWP-Scoring\회차별채점자료\2602"
|
||||
exam_round = "2602" # 회차명
|
||||
exam_code = "DIW" # 코드명
|
||||
# =======================
|
||||
source_dir = rf"D:\project\HWP\HWP-Scoring\회차별채점자료\{exam_round}"
|
||||
output_base = r"input"
|
||||
|
||||
types = ["A", "B", "C", "D", "E"]
|
||||
|
||||
def get_exam_type(filename: str):
|
||||
"""
|
||||
파일명에서 확장자 앞의 마지막 알파벳을 추출 (예: 국어A.hwpx → A)
|
||||
"""
|
||||
# match = re.search(r"([A-Za-z])\.hwpx$", filename)
|
||||
match = re.search(r'[A-Za-z](?=[^A-Za-z]*\.[^.]*$)', filename)
|
||||
return match.group().upper() if match else None
|
||||
# ── 복사 실행 ────────────────────────────────────────────────────────────
|
||||
for type in types:
|
||||
pattern = os.path.join(source_dir, f"*회 {type}형")
|
||||
matched = [d for d in glob.glob(pattern) if os.path.isdir(d)]
|
||||
|
||||
if not matched:
|
||||
print(f"[WARN] 폴더 없음: {pattern}")
|
||||
continue
|
||||
|
||||
def copy_exam_files():
|
||||
src = Path(source_dir)
|
||||
if not src.exists():
|
||||
print(f"경로를 찾을 수 없습니다: {src}")
|
||||
return
|
||||
src_folder = matched[0]
|
||||
|
||||
base_dest = Path(".") / "input" / exam_round
|
||||
copied = 0
|
||||
file_pattern = os.path.join(src_folder, f"제*회 디지털정보활용능력 워드프로세서(한글2022버전) {type}형 정답.hwpx")
|
||||
matched_files = glob.glob(file_pattern)
|
||||
|
||||
for path in src.rglob("*"):
|
||||
if path.is_file() and path.suffix.lower() == ".hwpx" and "정답" in path.name:
|
||||
exam_type = get_exam_type(path.name)
|
||||
if not exam_type:
|
||||
continue # 마지막 문자가 알파벳이 아니면 건너뜀
|
||||
if not matched_files:
|
||||
print(f"[WARN] 파일 없음: {file_pattern}")
|
||||
continue
|
||||
|
||||
dest_dir = base_dest / exam_type / exam_code
|
||||
dest_dir.mkdir(parents=True, exist_ok=True)
|
||||
dest_path = dest_dir / f"DIW_{exam_round}{exam_type}.hwpx"
|
||||
src_path = matched_files[0]
|
||||
|
||||
# 같은 이름의 파일이 있을 경우 숫자 붙이기
|
||||
counter = 1
|
||||
while dest_path.exists():
|
||||
dest_path = dest_dir / f"{path.stem}_{counter}{path.suffix}"
|
||||
counter += 1
|
||||
# 원본 확장자 추출 후 새 파일명 생성: DIW_2602A.hwpx
|
||||
src_ext = os.path.splitext(src_path)[1]
|
||||
new_filename = f"{exam_code}_{exam_round}{type}{src_ext}"
|
||||
|
||||
dst_folder = os.path.join(output_base, exam_round, type, exam_code)
|
||||
os.makedirs(dst_folder, exist_ok=True)
|
||||
|
||||
shutil.copy2(path, dest_path)
|
||||
print(f"복사 완료: {path} → {dest_path}")
|
||||
copied += 1
|
||||
dst_path = os.path.join(dst_folder, new_filename)
|
||||
shutil.copy2(src_path, dst_path)
|
||||
print(f"[OK] {type}형 복사 완료 → {dst_path}")
|
||||
|
||||
print(f"\n총 {copied}개 파일 복사 완료.")
|
||||
# ── TEST 폴더 생성 ────────────────────────────────────────────────────────
|
||||
test_folder = os.path.join(output_base, exam_round, type, "TEST")
|
||||
os.makedirs(test_folder, exist_ok=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
copy_exam_files()
|
||||
print("\n전체 처리 완료.")
|
||||
Reference in New Issue
Block a user