
폴더명에 한글이 들어간건 인코딩방식을 바꿔서 해결했는데
파일명은 아무리 해도 안됨
코랩에선 잘 되길래 디드어 태그 일일히 분류하던 중노동에서 해방이다 만세 하면서 로컬로 가져왔는데...
운영체제는 윈도우10이고 사용자명도 영문임
===========이하 스크린샷의 내용 복붙임===========
import os
import pyexiv2
# path.txt 파일이 있는 경우에는 파일에서 경로를 읽어옵니다.
if os.path.exists("path.txt"):
with open("path.txt", "r", encoding="utf-8") as f:
folder_path = f.read()
# path.txt 파일이 없는 경우에는 사용자로부터 경로를 입력받습니다.
else:
folder_path = input("폴더 경로를 입력하세요: ")
with open("path.txt", "w", encoding="utf-8") as f:
f.write(folder_path)
# 입력한 경로가 맞는지 검사합니다.
while not os.path.exists(folder_path):
print("잘못된 경로입니다.")
folder_path = input("폴더 경로를 다시 입력하세요: ")
with open("path.txt", "w", encoding="utf-8") as f:
f.write(folder_path)
# 폴더 내 모든 파일에 대해 XMP 데이터 수정
for filename in os.listdir(folder_path.encode("utf-8")):
filename = filename.decode("utf-8")
if filename.endswith(".jpg") or filename.endswith(".jpeg") or filename.endswith(".png"):
# 이미지 파일 열기
img_path = os.path.join(folder_path.encode("utf-8"), filename.encode("utf-8"))
img = pyexiv2.Image(img_path.decode("utf-8"))
# XMP 데이터를 담고 있는 텍스트 파일 경로
txt_path = os.path.join(folder_path, os.path.splitext(filename)[0] + ".txt")
# 텍스트 파일에서 XMP 데이터 읽어오기
with open(txt_path, "r", encoding="utf-8") as f:
tags_str = f.read().strip()
# 콤마 또는 세미콜론으로 구분된 태그를 리스트로 변환
tags = [t.strip() for t in tags_str.replace(",", ";").split(";")]
# XMP 데이터 수정
img.modify_xmp({'Xmp.dc.subject': tags})
# 이미지 파일 닫기
img.close()print("작업이 완료되었습니다.")
import pyexiv2
# path.txt 파일이 있는 경우에는 파일에서 경로를 읽어옵니다.
if os.path.exists("path.txt"):
with open("path.txt", "r", encoding="utf-8") as f:
folder_path = f.read()
# path.txt 파일이 없는 경우에는 사용자로부터 경로를 입력받습니다.
else:
folder_path = input("폴더 경로를 입력하세요: ")
with open("path.txt", "w", encoding="utf-8") as f:
f.write(folder_path)
# 입력한 경로가 맞는지 검사합니다.
while not os.path.exists(folder_path):
print("잘못된 경로입니다.")
folder_path = input("폴더 경로를 다시 입력하세요: ")
with open("path.txt", "w", encoding="utf-8") as f:
f.write(folder_path)
# 폴더 내 모든 파일에 대해 XMP 데이터 수정
for filename in os.listdir(folder_path.encode("utf-8")):
filename = filename.decode("utf-8")
if filename.endswith(".jpg") or filename.endswith(".jpeg") or filename.endswith(".png"):
# 이미지 파일 열기
img_path = os.path.join(folder_path.encode("utf-8"), filename.encode("utf-8"))
img = pyexiv2.Image(img_path.decode("utf-8"))
# XMP 데이터를 담고 있는 텍스트 파일 경로
txt_path = os.path.join(folder_path, os.path.splitext(filename)[0] + ".txt")
# 텍스트 파일에서 XMP 데이터 읽어오기
with open(txt_path, "r", encoding="utf-8") as f:
tags_str = f.read().strip()
# 콤마 또는 세미콜론으로 구분된 태그를 리스트로 변환
tags = [t.strip() for t in tags_str.replace(",", ";").split(";")]
# XMP 데이터 수정
img.modify_xmp({'Xmp.dc.subject': tags})
# 이미지 파일 닫기
img.close()print("작업이 완료되었습니다.")
================이상===================