Finding most recently edited file in python

后端 未结 8 1931
说谎
说谎 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:35

    • use os.walk to list files
    • use os.stat to get file modified timestamp (st_mtime)
    • put both timestamps and filenames in a list and sort it by timestamp, largest timestamp is most recently edited file.

提交回复
热议问题