Finding most recently edited file in python

后端 未结 8 2073
说谎
说谎 2021-02-02 02:57

I have a set of folders, and I want to be able to run a function that will find the most recently edited file and tell me the name of the file and the folder it is in.

F

8条回答
  •  暖寄归人
    2021-02-02 03:33

    If anyone is looking for an one line way to do it:

    latest_edited_file = max([f for f in os.scandir("path\\to\\search")], key=lambda x: x.stat().st_mtime).name
    

提交回复
热议问题