我发现这个目录检查网页上的代码并修改了一下,所以它会打印出添加的文件。有一个浮标每隔一段时间发送一次读数,但有时连接丢失,而不是一个文件发送多个文件。我需要程序根据创建日期为我排序。有没有办法做到这一点?按日期排序文件
import os, time
path_to_watch = 'c://Users//seplema//Documents//arvuti'
before = dict([(f, None) for f in os.listdir (path_to_watch)])
while 1:
after = dict([(f, None) for f in os.listdir (path_to_watch)])
added = [f for f in after if not f in before]
if before == after:
1==1
else:
if len(added)==1:
print added[0]
else:
for i in range (0,len(added)):
print added[i]
time.sleep(10)
before = after
http://stackoverflow.com/questions/168409/how-do-you-get-a-directory-listing-sorted-by-creation-date-in-python – Jacob