diff --git a/main.go b/main.go
index a0a1cd5..8b0820d 100644
--- a/main.go
+++ b/main.go
@@ -281,30 +281,20 @@ func listDirectory(w http.ResponseWriter, r *http.Request, root string) {
slog.Error("Error writing directory listing: " + err.Error())
return
}
- err = filepath.Walk(filepath.Join(root, filepath.FromSlash(r.URL.Path)), func(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
- relPath, err := filepath.Rel(root, path)
- if err != nil {
- return err
- }
- if relPath == "." {
- return nil
- }
- _, err = w.Write([]byte("
" + info.Name() + ""))
- if err != nil {
- serverError(w, 500)
- slog.Error("Error writing directory: " + err.Error())
- return err
- }
- return nil
- })
+ entries, err := os.ReadDir(filepath.Join(root, filepath.FromSlash(r.URL.Path)))
if err != nil {
serverError(w, 500)
- slog.Error("Error walking directory: " + err.Error())
+ slog.Error("Error listing directory: " + err.Error())
return
}
+ for _, entry := range entries {
+ _, err = w.Write([]byte("" + entry.Name() + ""))
+ if err != nil {
+ serverError(w, 500)
+ slog.Error("Error writing directory listing: " + err.Error())
+ return
+ }
+ }
_, err = w.Write([]byte("