from watchdog.observers import Observer
from watchdog.events import *
import time

class FileEventHandler(FileSystemEventHandler):
def __init__(self):
FileSystemEventHandler.__init__(self)

def on_moved(self, event):
if event.is_directory:
print("directory moved from {0} to {1}".format(event.src_path,event.dest_path))
else:
print("file moved from {0} to {1}".format(event.src_path,event.dest_path))

def on_created(self, event):
if event.is_directory:
print("directory created:{0}".format(event.src_path))
else:
print("file created:{0}".format(event.src_path))

def on_deleted(self, event):
if event.is_directory:
print("directory deleted:{0}".format(event.src_path))
else:
print("file deleted:{0}".format(event.src_path))

def on_modified(self, event):
if event.is_directory:
print("directory modified:{0}".format(event.src_path))
else:
print("file modified:{0}".format(event.src_path))

if __name__ == "__main__":
observer = Observer()
event_handler = FileEventHandler()
observer.schedule(event_handler,"d:/test",True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()

python 检测文件夹的数据变动的更多相关文章

  1. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  2. python 遍历文件夹 文件

    python 遍历文件夹 文件   import os import os.path rootdir = "d:\data" # 指明被遍历的文件夹 for parent,dirn ...

  3. python检测文件的MD5值

    python检测文件的MD5值MD5(单向散列算法)的全称是Message-Digest Algorithm 5(信息-摘要算法),经MD2.MD3和MD4发展而来.MD5算法的使用不需要支付任何版权 ...

  4. python 关于文件夹的操作

    在python中,文件夹的操作主要是利用os模块来实现的, 其中关于文件夹的方法为:os.lister() , os.path.join() , os.path.isdir() #  path 表示文 ...

  5. Python打包文件夹的方法小结(zip,tar,tar.gz等)

    本文实例讲述了Python打包文件夹的方法.分享给大家供大家参考,具体如下: 一.zip ? 1 2 3 4 5 6 7 8 9 10 11 import os, zipfile #打包目录为zip文 ...

  6. 用Python打开文件夹

    用Python读取文件夹, 然后打开文件 下面读取到文件的每一个内容, 然后加上路径 import os path = r'../Downloads/text/content' for filenam ...

  7. python检测文件的MD值

    使用hashlib模块,可对文件MD5一致性加密验证: #python 检测文件MD5值 #python version 2.6 import hashlib import os,sys #简单的测试 ...

  8. 如何使用python 新建文件夹以及递归创建文件夹

    转载:如何使用python 新建文件夹以及递归创建文件夹 | 酷python (coolpython.net) 1. os.mkdir 使用python创建文件夹,通常使用os.mkdir方法,在使用 ...

  9. Python遍历文件夹

    许多次需要用python来遍历目录下文件, 这一次就整理了记录在这里. 随实际工作,不定期更新. import os class FileTraversal: def __init__(self, r ...

随机推荐

  1. 解决分页浏览后搜索无数据的问题(VUE+element-ui)

    开发过程中发现了:浏览到第二页后.对数据进行查询时,后台返回的数据是空.原因是:当前页码为第二页.所以向后台发送请求的pageNumber=2,当pageNumber=1时.就可以查询到数据了. 所以 ...

  2. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---门面模式之HomeTheater[转]

      1unit uSubObject;   2   3interface   4   5type   6   7  { TAmplifier与TTuner,TCDPlayer,TDVDPlayer相互 ...

  3. 读书笔记--Head First Networking目录

    1.解决物理网络 2.规划网络布局 3.工具和故障排除 4.包分析 5.网络设备和流量 6.连接网络的路由器 7.路由协议 8.域名系统 9.监控和故障排除 10.无线网络 11.网络安全 12.网络 ...

  4. C# params 用法简介

    params 是C#的关键字, params主要是在声明方法时参数类型或者个数不确定时使用,关于params 参数数组,需掌握以下几点: 一.参数数组必须是一维数组 二.不允许将params修饰符与r ...

  5. css 始终让图片占满自适应盒子(图片不失真)

    要去上班了,时间比较紧,先把代码粘出来,原理慢慢讲 我来了,今天是农历七月八日,昨天是七夕,不知道为什么,突然通知放假半天(嘎嘎),好吧,没什么!!!走到半路的我看到通知,立马撤了.正好回来把这个原理 ...

  6. Linux预习

    目录 linux系统和unix系统的简介 linux系统和unix系统的简介 unix是什么:和widows一样 特点:多用户,多任务 同一时刻,多用户同时执行多项程序,互不干扰 GNU项目 就是一个 ...

  7. Lab1 ex1 物理页内存分配算法的实现

    调用流程如下 kern_init --> pmm_init-->page_init-->init_memmap--> pmm_manager->init_memmap 从 ...

  8. day36 07-Hibernate抓取策略:many-to-one上的抓取策略

    package cn.itcast.test; import java.util.List; import org.hibernate.Hibernate; import org.hibernate. ...

  9. js实现放大镜特效的实现方法

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  10. Hdu 1156

    题目链接 Brownie Points II Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...