2502회 채점자료 업로드
This commit is contained in:
@@ -1,40 +1,44 @@
|
||||
import os
|
||||
import shutil
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
# 검색할 루트 디렉터리와 파일 복사 대상 루트 디렉터리 설정
|
||||
root_dir = r"./" # 탐색할 루트 디렉터리
|
||||
output_root_dir = r"./" # 복사된 파일을 저장할 디렉터리
|
||||
def copy_dic_subdirs(source_root, target_root_a, target_root_b, target_root_c, target_root_d, target_root_e):
|
||||
for root, dirs, files in os.walk(source_root):
|
||||
for dir_name in dirs:
|
||||
if dir_name == 'DIW': # DIC 디렉토리 탐색
|
||||
parent_dir = os.path.basename(os.path.dirname(os.path.join(root, dir_name)))
|
||||
target_root = None
|
||||
parent_dir = unicodedata.normalize('NFC', parent_dir)
|
||||
|
||||
# 필요한 폴더 이름
|
||||
target_folders = ["1교시", "2교시", "3교시", "4교시"]
|
||||
|
||||
# 정규식 패턴
|
||||
pattern = r'^워드\(한글\).*\.hwp$'
|
||||
|
||||
# 출력 디렉터리에 '1교시', '2교시', '3교시' 폴더 생성
|
||||
for folder_name in target_folders:
|
||||
os.makedirs(os.path.join(output_root_dir, folder_name), exist_ok=True)
|
||||
|
||||
# 루트 디렉터리 탐색
|
||||
for dirpath, dirnames, filenames in os.walk(root_dir):
|
||||
for target_folder in target_folders:
|
||||
if target_folder in dirpath: # 현재 경로에 '1교시', '2교시', '3교시'가 포함되어 있는지 확인
|
||||
for file in filenames:
|
||||
if re.match(pattern, file): # 파일 이름이 정규식 패턴과 일치하는지 확인
|
||||
source_file = os.path.join(dirpath, file)
|
||||
destination_folder = os.path.join(output_root_dir, target_folder)
|
||||
destination_file = os.path.join(destination_folder, file)
|
||||
# 부모 디렉토리가 '2교시'인지, '3교시'인지 확인
|
||||
if parent_dir == '1교시':
|
||||
target_root = target_root_a
|
||||
elif parent_dir == '2교시':
|
||||
target_root = target_root_b
|
||||
elif parent_dir == '3교시':
|
||||
target_root = target_root_c
|
||||
elif parent_dir == '4교시':
|
||||
target_root = target_root_d
|
||||
elif parent_dir == '5교시':
|
||||
target_root = target_root_e
|
||||
|
||||
if target_root:
|
||||
source_dic_path = os.path.join(root, dir_name)
|
||||
target_dic_path = os.path.join(target_root, dir_name)
|
||||
|
||||
# 동일한 이름의 파일이 있으면 이름에 번호 추가
|
||||
counter = 1
|
||||
while os.path.exists(destination_file):
|
||||
base, ext = os.path.splitext(file)
|
||||
destination_file = os.path.join(destination_folder, f"{base}_{counter}{ext}")
|
||||
counter += 1
|
||||
|
||||
# 파일 복사
|
||||
shutil.copy2(source_file, destination_file)
|
||||
print(f"복사 완료: {source_file} → {destination_file}")
|
||||
# DIC 하위 디렉토리와 파일 복사
|
||||
shutil.copytree(source_dic_path, target_dic_path, dirs_exist_ok=True)
|
||||
print(f"Copied {source_dic_path} to {target_dic_path}")
|
||||
|
||||
else:
|
||||
print(f"Skipping {dir_name} under {parent_dir}, as it doesn't match '2교시' or '3교시'.")
|
||||
|
||||
print("모든 .hwp 파일 추출 완료!")
|
||||
# 사용법
|
||||
source_directory = r"C:\Users\dra\project\data\채점기준표+정답\2502\hwp_정답 - 복사본" # 원본 디렉토리 경로
|
||||
target_directory_a = r".\input\A" # '1교시'의 타겟 경로
|
||||
target_directory_b = r".\input\B" # '2교시'의 타겟 경로
|
||||
target_directory_c = r".\input\C" # '3교시'의 타겟 경로
|
||||
target_directory_d = r".\input\D" # '4교시'의 타겟 경로
|
||||
target_directory_e = r".\input\E" # '5교시'의 타겟 경로
|
||||
|
||||
copy_dic_subdirs(source_directory, target_directory_a, target_directory_b, target_directory_c, target_directory_d, target_directory_e)
|
||||
|
||||
Reference in New Issue
Block a user