python多线程监控指定目录
import win32file
import tempfile
import threading
import win32con
import os dirs=["C:\\WINDOWS\\TEMP",tempfile.gettempdir()]
def start_monitor(path_to_watch):
h_directory = win32file.CreateFile(path_to_watch, win32con.GENERIC_READ ,
win32con.FILE_SHARE_DELETE|win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE ,
None , win32con.OPEN_EXISTING , win32con.FILE_FLAG_BACKUP_SEMANTICS , None )
while True:
try:
results = win32file.ReadDirectoryChangesW(h_directory,1024, True,
win32con.FILE_NOTIFY_CHANGE_FILE_NAME|win32con.FILE_NOTIFY_CHANGE_DIR_NAME|
win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES|win32con.FILE_NOTIFY_CHANGE_SIZE|
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE|win32con.FILE_NOTIFY_CHANGE_SECURITY,
None)
for action, filename in results:
print action
print filename
except:
pass for path in dirs:
monitor_thread = threading.Thread(target=start_monitor,args=(path,))
monitor_thread.start()
python多线程监控指定目录,主要函数是
win32file.ReadDirectoryChangesW监控目录变化
ReadDirectoryChangesW(handle, size, bWatchSubtree, dwNotifyFilter, overlapped)
retrieves information describing the changes occurring within a directory.
Parameters
handle : PyHANDLE
Handle to the directory to be monitored. This directory must be opened with the FILE_LIST_DIRECTORY access right.
size : int
Size of the buffer to allocate for the results.
bWatchSubtree : int
Specifies whether the ReadDirectoryChangesW function will monitor the directory or the directory tree. If TRUE is specified, the function monitors the directory tree rooted at the specified directory. If FALSE is specified, the function monitors only the directory specified by the hDirectory parameter.
dwNotifyFilter : int
Specifies filter criteria the function checks to determine if the wait operation has completed. This parameter can be one or more of the FILE_NOTIFY_CHANGE_* values.
overlapped=None : PyOVERLAPPED
An overlapped object. The directory must also be opened with FILE_FLAG_OVERLAPPED.
python多线程监控指定目录的更多相关文章
- python之对指定目录文件夹的批量重命名
python之对指定目录文件夹的批量重命名 import os,shutil,string dir = "/Users/lee0oo0/Documents/python/test" ...
- 使用WatchService监控指定目录内的文件的改动
package coin; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Pat ...
- C#监控指定目录的文件变化的代码
如下的资料是关于C#监控指定目录的文件变化的代码. FileSystemWatcher watcher = new FileSystemWatcher();watcher.Path = @" ...
- [Erlang27]如何监控指定目录下的*.beam文件,如果有改动就更新到指定的节点?
在Erlang In Anger第二章中讲到使用rebar来创建一个Erlang项目(Application或Project) 但美中不足的只是给出了指引,但没有给出详细的步骤. 下面我们就使用reb ...
- linux下python安装到指定目录
由于使用公司服务器时没有root权限,只能把python安装到个人文件夹下,使用源码包方式安装,这里记录一下. 1.python下载 cd到目录/users/w,在此目录下安装python.通过wge ...
- VC++ 监控指定目录改变
转载:http://www.cnblogs.com/doublesnke/archive/2011/08/16/2141374.html VC++实施文件监控:实例和详解 相关帮助: http://h ...
- Python批量删除指定目录下的指定类型的文件
Python作为一种脚本语言.其很适合文件级的各种操作.以下的代码能够批量删除指定目录下的所有特定类型(CSV类型)的文件. import sys, csv , operator import os ...
- Python —— 批量替换指定目录下的所有文件中指定字符串
参考:http://blog.csdn.net/zcwfengbingdongguke/article/details/13951527 代码: #!/usr/bin/python import os ...
- python之删除指定目录指定日期下的日志文件
#=======================================================================================20190521以下脚本 ...
随机推荐
- Oracle logmnr工具分析日志脚本
在oracle:对logmnr工具分析日志这个不陌生:对数据恢复应用场景经常用到:这里为了方便对归档日志进行分析: 当然网上有一个logmnr界面的工具:感觉很人性化:下载需要积分:为此写一个脚本. ...
- lua 操作中文字符串之截取和长度竖排显示
前言 在游戏中,我们经常会遇到汉字的多行显示,比如名字竖行显示等.如下图: 为了实现上面的效果,lua实现分行是通过 \n 实现的,所以我们需要取出汉字,然后插入 \n 实现分行效果.还有一种就是 ...
- 【转】【C/C++】实现memcpy函数
本文转自:http://my.oschina.net/renhc/blog/36345 面试中如问到memcpy的实现,那就要小心了,这里有陷阱. 先看下标准memcpy()的解释: ? 1 2 vo ...
- shell & dialog
最近使用dialog写图形自动化shell脚本, 功能很强大,功能不是非常多但是足够用.想写一篇linux下dialog的使用方法,虽然命令不多,但是写起来也需要下很大功夫,而且不一定写得更好,在网 ...
- [转](一)unity4.6Ugui中文教程文档-------概要
转载请注明出处:http://blog.csdn.net/u010019717更全的内容请看我的游戏蛮牛地址:http://www.unitymanual.com/forum.php?mod=guid ...
- docker-registry使用笔记
在国内docker-hub是肯定用不了的,不解释:sweat:. 所以最好还是建一个私有的docker-registry,存储一些常用的images方便随时pull. 相关链接 github:http ...
- HTTP协议的头信息详解
转载地址:http://blog.csdn.net/guoguo1980/article/details/2649658 HTTP(HyperTextTransferProtocol)是超文本传输协议 ...
- 深入浅出设计模式——状态模式(State Pattern)
模式动机 在很多情况下,一个对象的行为取决于一个或多个动态变化的属性,这样的属性叫做状态,这样的对象叫做有状态的 (stateful)对象,这样的对象状态是从事先定义好的一系列值中取出的.当一个这样的 ...
- [Prodinner项目]学习分享_第一部分_Model层
事先声明一下,小弟我是菜鸟一个,在研究大半天之后,基本会开发一些简单的功能了,特此分享一下,也为自己做一个笔记. 项目简介: MVC4 , EF5 , Code First , 多层架构 开发工具:V ...
- 访问google.com
ping www.google.com 得到的IP来访问