Python: Find newest file with .MP3 extension in directory

后端 未结 5 1040
别那么骄傲
别那么骄傲 2020-12-12 17:55

I am trying to find the most recently modified (From here on out \'newest\') file of a specific type in Python. I can currently get the newest, but it doesn\'t matter what

5条回答
  •  悲哀的现实
    2020-12-12 18:42

    for file in os.listdir(os.getcwd()):
        if file.endswith(".mp3"):
            print "",file
            newest = max(file , key = os.path.getctime)
            print "Recently modified Docs",newest
    

提交回复
热议问题