Finding most recently edited file in python

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

    For multiple files, if anyone came here for that:

    import glob, os
    
    files = glob.glob("/target/directory/path/*/*.mp4")
    files.sort(key=os.path.getmtime)
    
    for file in files:
       print(file)
    

    This will print all files in any folder within /path/ that have the .mp4 extension, with the most recently modified file paths at the bottom.

提交回复
热议问题