Created
November 22, 2019 11:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
""" | |
# 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