-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-doc2md.py
More file actions
36 lines (35 loc) · 1.27 KB
/
task-doc2md.py
File metadata and controls
36 lines (35 loc) · 1.27 KB
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
31
32
33
34
35
36
import os
os.chdir('/home/anu/docfiles')
path = os.getcwd()
for root, dirs, files in os.walk('/home/anu/docfiles'):
for file in files:
if file.endswith('.doc'):
os.chdir('/home/anu/docfiles')
file_read = open(file, 'r',encoding='utf-8-sig')
reader = file_read.readlines()
os.chdir('/home/anu/docfiles')
for lines in reader:
print(lines)
if lines.startswith('Book'):
book = lines[-4:-1]
try:
os.mkdir(book)
except:
os.chdir(path)
elif lines.startswith('Chapter'):
chapter = lines[-3:-1]
os.chdir(path + '/' + book + '/')
try:
os.mkdir(chapter)
except:
os.chdir(path)
else:
os.chdir(path + '/' + book + '/' + chapter + '/')
if lines.startswith('Verse'):
verse = lines[-3:-1]
writer = open(verse + '.md', 'w')
else:
writer.write(lines)
os.chdir(path)
file_read.close()
writer.close()