import os
def getFileStructure(currentFile, father, tab):
workfilerename(currentFile)
basename = os.path.basename(currentFile)
if os.path.isfile(currentFile) and os.path.basename(currentFile).endswith(".md"):
newName = basename.replace(".md", "")
return father + "* [" + newName + "](" + currentFile + ")"
elif os.path.isdir(currentFile) and workfile(currentFile) == True:
fatherOrigin = "* [" + basename + "]()";
files = os.listdir(currentFile)
absolutPath = os.path.relpath(currentFile, ".")
if len(files) == 0:
return None
subStructure = []
for file in files:
newTab = tab + ' '
fileStructure = getFileStructure(absolutPath + "\\" + file, "", newTab)
if fileStructure != None:
subStructure.append(fileStructure)
if len(subStructure) == 0:
return None
for ele in subStructure:
fatherOrigin = fatherOrigin + "\n" + tab + ele
return fatherOrigin
def workfile(mypath):
for root, dirs, files in os.walk(mypath):
flag = False
for name in files:
if name.endswith(".md"):
flag = True
return flag
return flag
def workfilerename(mypath):
for root, dirs, files in os.walk(mypath):
for name in files:
if "(" in name or ")" in name:
newName = name.replace("(", "(").replace(")", ")")
namePath = os.path.join(root, name)
newNamePath = os.path.join(root, newName)
os.rename(namePath, newNamePath)
for dir in dirs:
if "(" in dir or ")" in dir:
newDir = dir.replace("(", "(").replace(")", ")")
dirPath = os.path.join(root, dir)
newDirPath = os.path.join(root, newDir)
os.rename(dirPath, newDirPath)
if __name__ == '__main__':
workfilerename(".")
path = os.path.curdir
current = os.listdir(path)
content = []
toBeWrite = ''
for currentFile in current:
workfilerename(currentFile)
structure = getFileStructure(currentFile, "", " ")
if structure != None:
content.append(structure)
print(content)
summary = open("SUMMARY.md", 'w', encoding='UTF-8')
for str in content:
toBeWrite = toBeWrite + '\n' + str
summary.write(toBeWrite)
summary.close()
Python版autoSummary脚本
未经允许不得转载:Stephen Young » Python版autoSummary脚本
相关推荐
-      阿里云ddns脚本全流程+python、pip环境安装
-      图片脚本上传最终版
-      python脚本文件遍历,字符串查找,图片上传
-      Pythonista
评论前必须登录!
注册