diff --git a/dir2html.py b/dir2html.py index f9355db..ed9a736 100644 --- a/dir2html.py +++ b/dir2html.py @@ -34,17 +34,27 @@ def ext(fname): def write_dir_listing(indirname, outfname): lines = [] outdirname = path.dirname(outfname) + try: + os.remove(outfname) # Avoid self-listing. + except FileNotFoundError: + pass for root, dirs, files in os.walk(indirname): + def file_filter(f): + stemName, extName = path.splitext(f) + if extName != ".html": + return False + if ext(stemName)[1:].lower() not in CEXTS: + return False + return True + + files = list(filter(file_filter, files)) if not files: continue files.sort() root = path.relpath(root, outdirname) - lines.append('
  • {0}: