Skip to content

Instantly share code, notes, and snippets.

@lilacs2039
Created November 22, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lilacs2039/515fcb223d98c985486a3316e9a16a9e to your computer and use it in GitHub Desktop.
Save lilacs2039/515fcb223d98c985486a3316e9a16a9e to your computer and use it in GitHub Desktop.
List up the MS Office files in sub folders, then output a html file.
"""
"""
# Variables
outFilename = "FileList.html"
outFilename_withFullpathStr = "FileList_withFullPath.html"
exts = ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf', '.msg']
# Programs **************
from pathlib import Path
#reference: https://qiita.com/amowwee/items/e63b3610ea750f7dba1b
p = Path(".")
print("target directory : ",p.cwd())
filelist = [img for img in p.glob('**/*') if img.suffix in exts]
print("detected files \r\n",filelist)
content = ["""
<head>
<meta charset="utf-8"/>
</head>
"""]
content_withFullpathStr = content[:]
for file in filelist:
content.append("<p> <a href=\""+str(file.absolute())+"\">"+str(file.name)+"</a></p>")
content_withFullpathStr.append(
"<p> <a href=\"" + str(file.absolute()) + "\">" + str(file.name) + "</a> " + str(file.absolute()) + " </p>")
# reference:https://note.nkmk.me/python-pathlib-file-open-read-write-unlink/
p_new = Path(outFilename)
p_new.write_text("\n".join(content), encoding='utf-8')
p_new = Path(outFilename_withFullpathStr)
p_new.write_text("\n".join(content_withFullpathStr), encoding='utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment