【发布时间】:2011-07-20 09:02:32
【问题描述】:
我在网上找到了这个目录检查代码并稍微修改了一下,所以它会打印出添加的文件。有一个浮标不时向我发送读数,但有时连接丢失,而不是一个文件,它发送多个文件。我需要程序按创建日期为我排序。有没有办法做到这一点?
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
【问题讨论】: