Created
May 5, 2018 15:04
-
-
Save doowonee/a1b9dfb4f178c7812c22aa261cccd467 to your computer and use it in GitHub Desktop.
텍스트 파일을 파싱하고 실제 파일명을 변경해주는 스크립트
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
윈도우에서만 사용 가능함 | |
이미지 태그가 존재하는 텍스트 파일을 파싱해서 그에 맞는 이미지 파일을 순서에 맞게 파일명을 변경해주는 스크립트. | |
텍스트파일에는 있지만 실제 파일이 없는 경우 표준출력으로 출력함 | |
''' | |
import re, os | |
# 이미지파일들이 존재 하는 경로 | |
IMG_FILES = 'd:/images' | |
# 파싱할 파일 | |
TXT_FILE = "d:/foo.html" | |
start = 0 | |
with open(TXT_FILE, 'r', encoding='utf-8') as f: | |
html_codes = f.read() | |
for matched in re.compile('\w+.jpg').findall(html_codes): | |
start += 1 | |
target = os.path.join(IMG_FILES, matched) | |
done = os.path.join(IMG_FILES, '{:04d}.jpg'.format(start)) | |
try: | |
os.rename(target, done) | |
#print('{} -> {}'.format(target, done)) | |
except FileNotFoundError: | |
print("{} doesn't exist! It should be {}".format(target, done)) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment