-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_title.py
More file actions
29 lines (26 loc) · 977 Bytes
/
list_title.py
File metadata and controls
29 lines (26 loc) · 977 Bytes
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
import re
import os
import sys
reg = '###.*\n'
if len(sys.argv)>1:
walk_dir = sys.argv[1]
else:
walk_dir = '.'
#print('walk_dir = ' + walk_dir)
# If your current working directory may change during script execution, it's recommended to
# immediately convert program arguments to an absolute path. Then the variable root below will
# be an absolute path as well. Example:
# walk_dir = os.path.abspath(walk_dir)
#print('walk_dir (absolute) = ' + os.path.abspath(walk_dir))
for root, subdirs, files in os.walk(walk_dir):
for filename in files:
file_path = os.path.join(root, filename)
if file_path.endswith('.md'):
print('%s' % (file_path))
with open(file_path, 'r') as f:
f_content = f.read()
result = re.findall(reg, f_content)
if len(result):
print(result[0])
#else:
# print('file %s not contains title\n' % file_path)