forked from arl/E-Books-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_all_books.py
30 lines (23 loc) · 819 Bytes
/
list_all_books.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import sys
rootdir = "./"
readme_str = '# IT e-books collection \r\n ---------- \r\n'
file_tree_str = ""
all_book = []
for dir in os.listdir(rootdir):
if os.path.isdir(dir) and dir != r".git":
readme_str += "## " + dir +"\r\n"
file_tree_str += dir + "\r\n"
for file in os.listdir(dir):
if file in all_book:
print("Duplicate book. Book Name: " + dir + "/" + file)
sys.exit(1)
if os.path.isfile(os.path.join(rootdir, dir, file)):
readme_str += file + "\r\n"
file_tree_str += " " + file + "\r\n"
all_book.append(file)
print(file_tree_str)
print("Total books: " + str(len(all_book)))
readme_file = open(r"readme.md", "w")
readme_file.write(readme_str)
readme_file.close()