How to use Python to generate Ebooks index
```
import os
import re
path = "."
p = re.compile(".+(\.pdf|\.epub|\.mobi|\.azw3)$")
text = ""
for root, dir_names, file_names in os.walk(path):
for name in file_names:
if p.match(name) != None:
#full_path = os.path.join(root, name)
#print(full_path)
print(name)
text += name + "\n"
with open("index.txt", "w", encoding="utf-8", errors="ignore") as f:
f.write(text + "\nMade by yingshaoxo")
```
If you want to copy all EPUB files to a certain folder:
```
import os
import re
from shutil import copyfile
try:
os.mkdir("../EPUB")
except Exception as e:
print(e)
path = os.path.abspath(".")
p = re.compile(".+(\.epub)$")
target_root = os.path.abspath("../EPUB")
for root, dir_names, file_names in os.walk(path):
for name in file_names:
if p.match(name) != None:
full_path = os.path.join(root, name)
print(full_path)
copyfile(full_path, os.path.join(target_root, name))
```
import os
import re
path = "."
p = re.compile(".+(\.pdf|\.epub|\.mobi|\.azw3)$")
text = ""
for root, dir_names, file_names in os.walk(path):
for name in file_names:
if p.match(name) != None:
#full_path = os.path.join(root, name)
#print(full_path)
print(name)
text += name + "\n"
with open("index.txt", "w", encoding="utf-8", errors="ignore") as f:
f.write(text + "\nMade by yingshaoxo")
```
If you want to copy all EPUB files to a certain folder:
```
import os
import re
from shutil import copyfile
try:
os.mkdir("../EPUB")
except Exception as e:
print(e)
path = os.path.abspath(".")
p = re.compile(".+(\.epub)$")
target_root = os.path.abspath("../EPUB")
for root, dir_names, file_names in os.walk(path):
for name in file_names:
if p.match(name) != None:
full_path = os.path.join(root, name)
print(full_path)
copyfile(full_path, os.path.join(target_root, name))
```