Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pathlib import Path
- import re
- import os
- import shutil
- p = Path("")
- books = list(p.glob('*.html'))
- book_ids = {}
- tot_books = 0
- tot_frontmatter = 0
- for book in books:
- if "book-" in book.stem:
- book_id = re.match(r'.*book-(.*)\)', book.stem).group(1)
- book_ids[book_id] = book_ids.get(book_id, []) + [book.stem]
- if "frontmatter" in book.stem:
- tot_frontmatter += 1
- for key in book_ids.keys():
- os.mkdir(key)
- for book in book_ids[key]:
- shutil.move(book + ".html", key + "/" + book + ".html")
Advertisement
Add Comment
Please, Sign In to add comment