diff --git a/Lib/http/server.py b/Lib/http/server.py index ebc85052aecb90..8876658def6831 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -872,13 +872,13 @@ def list_directory(self, path): """ try: - list = os.listdir(path) + with os.scandir(path) as it: + entries = sorted(it, key=lambda e: e.name.lower()) except OSError: self.send_error( HTTPStatus.NOT_FOUND, "No permission to list directory") return None - list.sort(key=lambda a: a.lower()) r = [] displaypath = self.path displaypath = displaypath.split('#', 1)[0] @@ -899,15 +899,24 @@ def list_directory(self, path): r.append(f'{title}\n') r.append(f'\n

{title}

') r.append('
\n