28 lines
1.2 KiB
Python
Executable File
28 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
from datetime import datetime
|
|
|
|
def mkindex(DIR):
|
|
FILE = os.path.join(DIR, 'index.html')
|
|
with open(FILE, 'w') as index:
|
|
index.write(f'<html><head><title>Index of {DIR}</title></head><body style="font-family: monospace;"><h1>Index of {DIR}</h1><hr>')
|
|
index.write(f'<p>Generated on {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}</p>')
|
|
index.write('<table width=500><thead align="left"><tr><th>Name</th><th>Last Modified</th></tr></thead><tbody>')
|
|
entries = os.listdir(DIR)
|
|
entries = sorted([entry for entry in entries if not entry.startswith('.')])
|
|
for file in entries:
|
|
if os.path.isdir(os.path.join(DIR, file)):
|
|
file += '/'
|
|
timestamp = datetime.fromtimestamp(os.path.getmtime(os.path.join(DIR, file))).strftime('%Y-%m-%d %H:%M:%S')
|
|
index.write(f'<tr><td><a href="{file}">{file}</a></td><td><span style="color: #888;">{timestamp}</span></td></tr>')
|
|
index.write('</tbody></table></body></html>')
|
|
|
|
def index_for_all(DIR):
|
|
mkindex(DIR)
|
|
for d in os.listdir(DIR):
|
|
if os.path.isdir(os.path.join(DIR, d)):
|
|
index_for_all(os.path.join(DIR, d))
|
|
|
|
index_for_all(os.getcwd())
|