asfsd 发表于 2018-8-7 12:26:03

python 监控文件目录变化

#!/usr/bin/env python  
#-*- coding=utf-8 -*-
  
#filename: monitor_dir.py
  
import os
  
import time
  
monitor_dir = "/opt/"
  
now_file = dict([(f,None)forf in os.listdir(monitor_dir)])
  
while True:
  
    new_file = dict([(f,None)forf in os.listdir(monitor_dir)])
  
    added =
  
    removed =
  
    if added:
  
      print ("Added:",",".join(added))
  
    if removed:
  
      print ("Removed:",",".join(removed))
  
    now_file = new_file
页: [1]
查看完整版本: python 监控文件目录变化