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以下脚本 ...
随机推荐
- SIP协议栈基础笔记
//------------------SIP基础------------------------// SIP是基于UDP的协议 UA(user Agent)用户代理 UAC(client)发起SIP ...
- js与jsp
jsp :j2ee 中的一样模版技术,运行于服务器端javascript :一种运行于客户端的脚本语言,动态性.JavaScript是一种采用事件驱动的脚本语言,它不需要经过Web服务器就可以对用户的 ...
- Linq join on 多条件
var a = from m in DbContext.Set<T1>() join q in DbContext.Set<T2>() on new { m.ID, Phone ...
- 理解JS回调函数
我们经常会用到客户端与Web项目结合开发的需求,那么这样就会涉及到在客户端执行前台动态脚本函数,也就是函数回调,本文举例来说明回调函数的过程. 首先创建了一个Web项目,很简单的一个页面,只有一个bu ...
- Learning Roadmap of Deep Reinforcement Learning
1. 知乎上关于DQN入门的系列文章 1.1 DQN 从入门到放弃 DQN 从入门到放弃1 DQN与增强学习 DQN 从入门到放弃2 增强学习与MDP DQN 从入门到放弃3 价值函数与Bellman ...
- JPA入门案例详解(附源码)
1.新建JavaEE Persistence项目
- aws在线技术峰会笔记-基于AWS的Devops最佳实践
AWS CodeCommit AWS CodePipeline 可以和github集成 可以支持蓝绿部署 微服务架构, API Gateway进行转发
- GIS服务器需求分析
一. 需求概要 1 边界 核心职责 接收并存储外部各方系统GPS数据 GPS数据实时分发, 轨迹检索 2 流程 GIS客户端向GIS服务器订购 GIS客户端向GIS服务器订购号码(仅有号码这一项业 ...
- Nginx模块之————RTMP模块在Ubuntu 14.04年的设置与搭建
Nginx的设置,RTMP在Ubuntu 14.04 https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04
- java程序调用存储过程
java程序调用存储过程 PL/SQL子程序,很多情况下是给应用程序来调用的,所有我们要掌握使用其他编程语言来调用我们写好的存储过程.下面我们介绍下使用java调用Oracle的存储过程. ...