Skip to content

Commit 856eef4

Browse files
committed
shows file list for root dir
1 parent eadb566 commit 856eef4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

gurgleapps_webserver.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,15 @@ def blink_element(element, pin, duration=0.27):
301301
await asyncio.sleep(delay_between_repititions)
302302

303303
def list_files_and_folders(self, path):
304-
files_and_folders = os.listdir(path)
304+
entries = uos.ilistdir(path)
305+
files_and_folders = []
306+
for entry in entries:
307+
name = entry[0]
308+
mode = entry[1]
309+
if mode & 0o170000 == 0o040000: # Check if it's a directory
310+
files_and_folders.append({"name": name, "type": "directory"})
311+
elif mode & 0o170000 == 0o100000: # Check if it's a file
312+
files_and_folders.append({"name": name, "type": "file"})
305313
return files_and_folders
306314

307315
def generate_root_page_html(self, files_and_folders):
@@ -317,8 +325,8 @@ def generate_root_page_html(self, files_and_folders):
317325
"""
318326
file_list_html = "<ul class='list-none'>"
319327
for file_or_folder in files_and_folders:
320-
icon = folder_icon_svg if os.path.isdir(os.path.join("www", file_or_folder)) else file_icon_svg
321-
file_list_html += f"<li class='my-2'><a href='/{file_or_folder}' class='text-blue-600 hover:text-blue-800'>{icon} {file_or_folder}</a></li>"
328+
icon = folder_icon_svg if file_or_folder['type']=='directory' else file_icon_svg
329+
file_list_html += f"<li class='my-2'><a href='/{file_or_folder['name']}' class='text-blue-600 hover:text-blue-800'>{icon} {file_or_folder['name']}</a></li>"
322330
file_list_html += "</ul>"
323331

324332
html_content = f"""

0 commit comments

Comments
 (0)