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以下脚本 ...
随机推荐
- [充电]C++ string字符串替换
//C++ 第一种替换字符串的方法用replace()|C++ 第二种替换字符串的方法用erase()和insert()[ C++string|C++ replace()|C++ erase()|C+ ...
- android在全屏下第一次触摸屏幕没有触发事件
A.设置全屏的方法很多就不多说了,常见如下两种(记录用以备忘): 1.在Androidmanifest.xml文件中设定,如: <activity android:name="com. ...
- 2015弱校联盟(2) - J. Usoperanto
J. Usoperanto Time Limit: 8000ms Memory Limit: 256000KB Usoperanto is an artificial spoken language ...
- 关于ifram之间的相互调用
window.iframeId.btnClose.click(); 父调子 window.parent.FatherFunciton(); 子调父
- 使用HttpClient发送数据 到WebApi
发送和JSON数据 /=============================webAPI接受POST的JOSN数据=============================/ POST api/& ...
- 深入理解为什么Java中方法内定义的内部类可以访问方法中的局部变量
好文转载:http://blog.csdn.net/zhangjg_blog/article/details/19996629 开篇 在我的上一篇博客 深入理解Java中为什么内部类可以访问外部类的成 ...
- 弹窗的封装(css,js) 和弹窗的例子
//每个弹窗的标识 var x =0; var idzt = new Array(); var Window = function(config){ //ID不重复 idzt[x] = "z ...
- [四校联考P3] 区间颜色众数 (主席树)
主席树 Description 给定一个长度为 N 颜色序列A,有M个询问:每次询问一个区间里是否有一种颜色的数量超过了区间的一半,并指出是哪种颜色. Input 输入文件第一行有两个整数:N和C 输 ...
- JS历史
JavaScript伴随着互联网的发展一起发展.互联网周边技术的快速发展,刺激和推动了JavaScript语言的发展. 2006年,jQuery函数库诞生,作者为John Resig.jQuery为操 ...
- 0030 Linux 网络操作命令
1. 主机是否可达 ping IP 2. 服务是否在运行 telnet IP port 3. 网络配置 ifconfig ip route arp 4. 网络访问 curl wget 5. 网络追踪 ...