擅长:python、mysql、java
<p>以下是我给你的解决方案:</p>
<pre><code>import os
from datetime import datetime
def getNewestFiles(startpath):
path = ""
currTime = 0
maxTime = 0
resultPath = ""
for root, dirs, files in os.walk(startpath): #search from start to all folders and files
maxTime = 0
resultPath = ""
for f in files:
path = root+"\\"+f
currTime = os.path.getmtime(path) #get time of file
if(currTime > maxTime): #compare time with other files
maxTime = currTime
resultPath = path #take the largest number
if(resultPath != ""):
print('{} : {}'.format(resultPath, datetime.fromtimestamp(float(os.path.getmtime(resultPath))).strftime('%Y-%m-%d %H:%M:%S')))
</code></pre>
<p>你必须选择你的开始路径,然后你得到所有目录中的所有最新文件</p>