Finding most recently edited file in python

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

    Use os.path.walk() to traverse the directory tree and os.stat().st_mtime to get the mtime of the files.

    The function you pass to os.path.walk() (the visit parameter) just needs to keep track of the largest mtime it's seen and where it saw it.

提交回复
热议问题