2025-08-29 18:22:31 +09:00
|
|
|
# 분류된 "과목별" 폴더에서 시험 파일을 복사하는 스크립트
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
def copy_exam_files(exam_round, exam_codes, source_dir):
|
|
|
|
|
"""
|
|
|
|
|
시험 파일을 지정된 출력 폴더로 복사합니다.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
exam_round (str): 시험 회차 (예: "2507")
|
|
|
|
|
exam_codes (list): 시험 코드 리스트 (예: ["DIC", "DPI"])
|
|
|
|
|
source_dir (str): 기본 소스 디렉토리 경로
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
created_test_folders = set() # TEST 폴더 중복 생성을 막기 위한 집합
|
|
|
|
|
|
|
|
|
|
for exam_code in exam_codes:
|
|
|
|
|
code_dir = os.path.join(source_dir, exam_code)
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(code_dir):
|
|
|
|
|
print(f"⚠️ {exam_code} 디렉토리가 존재하지 않습니다.")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# 폴더 이름이 A, B, C...로 시작하는 폴더만 인식
|
|
|
|
|
exam_types = []
|
|
|
|
|
for item in os.listdir(code_dir):
|
|
|
|
|
match = re.match(r"^([A-Z])", item)
|
|
|
|
|
if match:
|
|
|
|
|
exam_types.append((match.group(1), item)) # ("A", "A형" 또는 "A_정답")
|
|
|
|
|
|
|
|
|
|
if not exam_types:
|
|
|
|
|
print(f"⚠️ 시험 유형 디렉토리가 없습니다: {exam_code}")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
for exam_type, real_folder in exam_types:
|
|
|
|
|
source_folder = os.path.join(code_dir, real_folder)
|
|
|
|
|
target_path = os.path.join(".", "input", exam_round, exam_type, exam_code)
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(source_folder):
|
|
|
|
|
print(f"⚠️ 건너뜀: {source_folder} 경로가 존재하지 않습니다.")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
os.makedirs(target_path, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
# ✅ TEST 폴더 생성: input/회차/유형/TEST
|
|
|
|
|
# test_folder = os.path.join("output", exam_round, exam_type, "TEST")
|
|
|
|
|
# if test_folder not in created_test_folders:
|
|
|
|
|
# os.makedirs(test_folder, exist_ok=True)
|
|
|
|
|
# created_test_folders.add(test_folder)
|
|
|
|
|
|
|
|
|
|
print(f"\n🔄 복사 시작: {exam_code} - 유형: {exam_type} (폴더명: {real_folder})")
|
|
|
|
|
print(f"📂 원본 경로: {source_folder}")
|
|
|
|
|
print(f"📂 대상 경로: {target_path}")
|
|
|
|
|
print("-" * 60)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
for item in os.listdir(source_folder):
|
|
|
|
|
source_item = os.path.join(source_folder, item)
|
|
|
|
|
target_item = os.path.join(target_path, item)
|
|
|
|
|
|
|
|
|
|
if os.path.isdir(source_item):
|
|
|
|
|
shutil.copytree(source_item, target_item, dirs_exist_ok=True)
|
|
|
|
|
print(f"📁 폴더 복사: {source_item} ➡️ {target_item}")
|
|
|
|
|
else:
|
|
|
|
|
shutil.copy2(source_item, target_item)
|
|
|
|
|
print(f"📄 파일 복사: {source_item} ➡️ {target_item}")
|
|
|
|
|
|
|
|
|
|
print("-" * 60)
|
|
|
|
|
print(f"✅ 복사 완료: {exam_code} - {exam_type}")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print("-" * 60)
|
|
|
|
|
print(f"❌ 오류 발생: {exam_code} - {exam_type} - {e}")
|
|
|
|
|
|
|
|
|
|
# 사용 예시
|
|
|
|
|
if __name__ == "__main__":
|
2025-10-29 16:19:12 +09:00
|
|
|
# [source_dir경로\DIW] 디렉토리 안에 A형, B형... 폴더가 존재해야 함
|
2025-11-14 16:17:53 +09:00
|
|
|
exam_round = "2510"
|
2025-08-29 18:22:31 +09:00
|
|
|
exam_codes = ["DIW"]
|
2025-11-14 16:17:53 +09:00
|
|
|
source_dir = r"D:\project\data\제2510회 정기\과목별답안파일"
|
2025-08-29 18:22:31 +09:00
|
|
|
|
|
|
|
|
copy_exam_files(exam_round, exam_codes, source_dir)
|