각 폴더에 저장된 JPG 파일 리스트 HTML로 만들기 > 자유게시판

본문 바로가기
  • 회원로그인

    아이디 비밀번호
  • 접속자 76
사이트 내 전체검색

자유게시판

각 폴더에 저장된 JPG 파일 리스트 HTML로 만들기

페이지 정보

본문

시간 날때 마다 보려고 웹툰을 미리 다운 받아서 저장 해 놓았으나 기존 만화 파일과는 다르게 일반 뷰어에서는 보기 힘들어서 폴더내의 JPG 파일 리스트를 추출해서 html로 저장하는 프로그램을 간단히 만들어 봤습니다.


파이썬입니다.



# -*- coding: utf-8 -*-

import os

import tkinter

from tkinter import filedialog

from PIL import Image


root = tkinter.Tk()

root.withdraw()


def createDirectory(directory):

    try:

        if not os.path.exists(directory):

            os.makedirs(directory)

    except OSError:

        print("Error: Failed to create the directory.")

        

def create_list(main_path,path) :

    file_list=os.listdir(path)

    html_path = main_path+"/html"

    createDirectory(html_path)

    html_file_name = html_path+"/"+path.split("\\")[-1]+".html"

    f = open(html_file_name, 'w')

    f.write("<center>")

    get_jpg_size = 1

    file_list_jpg=[file for file in file_list if file.endswith(".jpg")] 

    for file_name in file_list_jpg:

        if get_jpg_size == 1 :

            jpg_file_path = os.path.join(path,file_name).replace("\\","/")

            jpg_image = Image.open(jpg_file_path)

            jpg_w,jpg_h = jpg_image.size

            get_jpg_size = 0

        html_file_name = '<img src="..\\..\\'+path.split("/")[-1]+"\\"+file_name+'" width='+str(jpg_w)+'><br>'

        f.write(html_file_name)

    f.write("</center>")

    f.close()

    

main_path=filedialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')

dirs = os.listdir(main_path)

f_list = open(main_path+"/list.html", 'w')

f_list.write('<!DOCTYPE html><html><head><title>'+main_path+'</title></head><body><center>')

first_file_name = 0


for file in dirs:

    root_path = os.path.join(main_path, file)

    if os.path.isdir(root_path):

        dir_name = root_path.split("\\")[-1]

        if first_file_name == 0:

            first_file_name = dir_name

        if dir_name != "html":

            create_list(main_path,root_path)

            f_list.write('<a href=".\\html\\'+dir_name+'.html" target=cartoon>'+dir_name+'</a><br>')

            last_file_name = dir_name

f_list.write('</center></body></html>')

f_list.close()


f_list = open(main_path+"/main.html", 'w')

f_list.write('<!DOCTYPE html><html><head><title>'+main_path+'</title></head><body><h3>'+main_path.split('/')[-1]+' 총'+last_file_name+'회</h3><center>')

f_list.write('<iframe src="list.html" width=15% height=1024 frameborder=0 name=list align=left></iframe>')

f_list.write('<iframe src="./html/'+first_file_name+'.html" width=80% height=2048 name=cartoon frameborder=0  align=right></iframe>')

f_list.write('</center></body></html>')

f_list.close()


댓글목록

profile_image
Total 214건 1 페이지
자유게시판 목록
번호 제목 글쓴이 조회 날짜
공지 나너우리쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8711 11-23
213 나너우리쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 20019 12-01
212 no_profile 삐딱하게쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 15981 12-01
211 쌍둥아범/澤메일보내기 이름으로 검색 15138 12-01
210 박성철이름으로 검색 18652 12-01
209
(^^)(__)(^^) 댓글1
no_profile 액면23세예쁜Sandy언냐쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 15951 12-01
208 no_profile 용준짱쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 17060 12-01
207 김영순/茉莉花메일보내기 이름으로 검색 15206 12-02
206 no_profile 무리무리쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 16190 12-02
205 소심보이이름으로 검색 21100 12-02
204 연어메일보내기 이름으로 검색 19542 12-04
203 no_profile 관람객쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 21108 12-04
202 리공이름으로 검색 20750 12-04
201 방통메일보내기 이름으로 검색 18752 12-04
200 widetent이름으로 검색 17417 12-04
199 나너우리쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 18531 12-05
198 홍용기메일보내기 이름으로 검색 19195 12-05
197 no_profile 영채아빠쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 17534 12-05
196 no_profile 초락쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 23772 12-05
195 no_profile pm08쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 16300 12-05
194 no_profile songcatcher쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 16249 12-06
193 김병삼메일보내기 이름으로 검색 19053 12-06
192 이종화이름으로 검색 20121 12-06
191 no_profile 삼무처사쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 16566 12-06
190 no_profile goatjin쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 16858 12-06
189 고영규메일보내기 이름으로 검색 18525 12-06
188 형동생메일보내기 이름으로 검색 21209 12-06

검색


Copyright © 소유하신 도메인. All rights reserved.