标签:python os.listdir 监控目录
使用os.listdir()监控文件目录:#!/usr/bin/env python #-*- coding=utf-8 -*- #filename: monitor_dir.py import os import time monitor_dir = "/opt/" now_file = dict([(f,None)for f in os.listdir(monitor_dir)]) while True: new_file = dict([(f,None)for f in os.listdir(monitor_dir)]) added = [f for f in new_file if not f in now_file] removed = [f for f in now_file if not f in new_file] if added: print ("Added:",",".join(added)) if removed: print ("Removed:",",".join(removed)) now_file = new_file
标签:python os.listdir 监控目录
原文地址:http://blog.51cto.com/guoshiwei/2125161