From 255ed5944fa38fd79e1f330357341e6c37ca1ec8 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 10 Jan 2025 11:36:54 +0800 Subject: [PATCH] Update file.py --- web/utils/file.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/utils/file.py b/web/utils/file.py index 237f217b7..002526b77 100644 --- a/web/utils/file.py +++ b/web/utils/file.py @@ -496,10 +496,17 @@ def saveBody(path, data, encoding): def sortFileList(path, ftype = 'mtime', sort = 'desc'): flist = os.listdir(path) if ftype == 'mtime': - if sort == 'desc': - flist = sorted(flist, key=lambda f: os.path.getmtime(os.path.join(path,f)), reverse=True) - if sort == 'asc': - flist = sorted(flist, key=lambda f: os.path.getmtime(os.path.join(path,f)), reverse=False) + try: + if sort == 'desc': + flist = sorted(flist, key=lambda f: os.path.getmtime(os.path.join(path,f)), reverse=True) + if sort == 'asc': + flist = sorted(flist, key=lambda f: os.path.getmtime(os.path.join(path,f)), reverse=False) + except Exception as e: + if sort == 'desc': + flist = sorted(flist, key=lambda f: os.path.getctime(os.path.join(path,f)), reverse=True) + if sort == 'asc': + flist = sorted(flist, key=lambda f: os.path.getctime(os.path.join(path,f)), reverse=False) + if ftype == 'size': if sort == 'desc':