-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_md_files.py
54 lines (46 loc) · 1.78 KB
/
find_md_files.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
import os
from os import listdir, getcwd, chdir, makedirs
from os.path import isdir, isfile, join, expanduser
from shutil import copyfile
list_of_md_files = []
file_matches = 0
name_matches = 0
def find_md_files(sourcePath):
for item in listdir(sourcePath):
itemPath = join(sourcePath,item)
if isfile(itemPath) and item.endswith(".md"):
original_name = item.replace('_zh_CN','')
list_of_md_files.append(original_name)
if isdir(itemPath):
find_md_files(itemPath)
def find_md_matches(sourcePath):
global file_matches
global name_matches
for item in listdir(sourcePath):
itemPath = join(sourcePath,item)
if isfile(itemPath) and item.endswith(".md"):
counter = 0
with open(itemPath) as f:
lines = f.readlines()
for line in lines:
for md_file in list_of_md_files:
md_name = md_file.replace('.md','')
if md_file in line:
print(md_file + " md file name match in " + itemPath + " at line " + str(counter))
print(line)
file_matches += 1
elif md_name in line:
if counter != 0:
print(md_name + " ref name match found in " + itemPath + " at line " + str(counter))
print(line)
name_matches += 1
counter += 1
if isdir(itemPath):
find_md_matches(itemPath)
path = "."
find_md_files(path)
print(list_of_md_files)
find_md_matches(path)
print(str(file_matches) + " md file matches found.")
print(str(name_matches) + " name matches found.")