카테고리 없음
unzip
pishio
2025. 7. 2. 09:10
import tarfile
import os
import glob
# 현재 폴더 기준
current_dir = os.getcwd()
# 현재 폴더 내 모든 .tar.gz 파일 찾기
tar_files = glob.glob(os.path.join(current_dir, '*.tar.gz'))
for tar_path in tar_files:
try:
# 압축 파일 이름에서 .tar.gz 제거
base_name = os.path.basename(tar_path)
name_without_ext = base_name.replace('.tar.gz', '')
# 압축 해제 폴더 생성
extract_dir = os.path.join(current_dir, name_without_ext)
os.makedirs(extract_dir, exist_ok=True)
# 압축 해제
with tarfile.open(tar_path, 'r:gz') as tar:
tar.extractall(path=extract_dir)
print(f"[✔] '{base_name}' 압축 해제 완료 → {extract_dir}")
except Exception as e:
print(f"[✘] '{tar_path}' 압축 해제 실패: {e}")