학습 목적으로 @Kevin Vincent와 기본적으로 동일하지만, 읽기 쉽고 이해하기가 더 쉽습니다.
import datetime
import glob
import os
mp3Dir = "C:/mp3Dir/"
filesInmp3dir = os.listdir(mp3Dir)
datedFiles = []
for currentFile in filesInmp3dir:
if currentFile.lower().endswith('.mp3'):
currentFileCreationDateInSeconds = os.path.getmtime(mp3Dir + "/" + currentFile)
currentFileCreationDateDateObject = datetime.date.fromtimestamp(currentFileCreationDateInSeconds)
datedFiles.append([currentFileCreationDateDateObject, currentFile])
datedFiles.sort();
datedFiles.reverse();
print datedFiles
latest = datedFiles[0][1]
print "Latest file is: " + latest
'os'는 무엇입니까? – enginefree
@enginefree : Python과 함께 제공되는 표준 라이브러리의 모듈입니다. 'import os'를 작성하면 [모듈의 모든 유용한 기능] (http://docs.python.org/2/library/os.html)을 호출 할 수 있습니다. – abarnert
@abarnert'os' 모듈이 무엇인지 압니다. 나는 내가 그런 말을하지 않았다고 맹세한다. 내 계정이나 다른 것을 두 번 열어야합니다. 혼동을 피하기 위해 – enginefree