我试图在Python中找到最近修改过的(从此处开始'最新')特定类型的文件.我现在可以获得最新版本,但无论哪种类型都无关紧要.我想只获得最新的MP3文件.
目前我有:
import os
newest = max(os.listdir('.'), key = os.path.getctime)
print newest
Run Code Online (Sandbox Code Playgroud)
有没有办法修改它只给我最新的MP3文件?
我正在编写一个脚本,我试图列出以.xls结尾的最新文件.它应该很容易,但我收到一些错误.
码:
for file in os.listdir('E:\\Downloads'):
if file.endswith(".xls"):
print "",file
newest = max(file , key = os.path.getctime)
print "Recently modified Docs",newest
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "C:\Python27\sele.py", line 49, in <module>
newest = max(file , key = os.path.getctime)
File "C:\Python27\lib\genericpath.py", line 72, in getctime
return os.stat(filename).st_ctime
WindowsError: [Error 2] The system cannot find the file specified: 'u'
Run Code Online (Sandbox Code Playgroud)