Show sourcecode
The following files exists in this folder. Click to view.
public_html/gamla-kurser/webbutv2/övningar/
index.html
js_array/
js_for/
js_grunder/
js_start/
js_timers/
js_villkor/
js_while/
update_webbutv.py
update_webbutv.py
54 lines UTF-8 Windows (CRLF)
import os
dir_path = "./"
output_file = "index.html"
folder_count = 0
file_count = 0
html_content = """
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Övningar Webbutv2</title>
<link rel="stylesheet" href="../css/css_index.css">
</head>
<body>
<!-- <button onclick="location.href='../../index.html'" id="homebutton">Tillbaka</button> -->
<h1>Övningar webbutv2</h1>
<div id="lists">
"""
# Iterate through each folder in the directory
for folder_name in os.listdir(dir_path):
folder_path = os.path.join(dir_path, folder_name)
if os.path.isdir(folder_path):
html_content += f" <div class=\"card\">\n"
html_content += f" <h2>{folder_name.upper()}</h2>\n"
html_content += f" <ul>\n"
folder_count += 1
# Iterate through each file in the folder
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
if os.path.isfile(file_path):
relative_path = os.path.relpath(file_path, ".")
html_content += f" <li><a href={relative_path}>{file_name}</a></li>\n"
file_count += 1
html_content += " </ul>\n"
html_content += f" </div>\n"
html_content += """
</div>
</body>
</html>
"""
# Write the HTML content to the output file
with open(output_file, "w", encoding="utf-8") as file:
file.write(html_content)
print(f"HTML file '{output_file}' has been updated.")
print(f"Added {folder_count} folders and {file_count} files.")