How to sort files in a pie-cham project by date modified

Asked 2 years ago, Updated 2 years ago, 75 views

I can't figure out how to sort files by date crying Is it not possible to sort by selecting one name, date, file size, etc. like window??

pycharm sorting file

2022-09-22 18:44

1 Answers

Method of sorting by file date. I think you can find a lot of files if you search for Python sort().

python.py

import os

def getfiles(dirpath):
    filelist = [s for s in os.listdir(dirpath)
        if os.path.isfile(os.path.join(dirpath, s))]
    filelist.sort(key=lambda s: os.path.getmtime(os.path.join(dirpath, s)))
    return filelist

file1 = getfiles ('file list folder path')


2022-09-22 18:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.