C++监测文件夹变化

该博客介绍了一个C++实现的文件系统监视器,能够监控指定文件夹的变化,包括添加、删除、修改和重命名事件。通过Windows API实现,提供了一个回调函数接口来处理各种操作。
摘要由CSDN通过智能技术生成

 

//FileSystemWatcher.h

#ifndef __FILESYSTEMWATCHER_HPP__
#define __FILESYSTEMWATCHER_HPP__

#if(_WIN32_WINNT < 0x0400)
#define _WIN32_WINNT 0x0400
#endif
#include <windows.h>

class FileSystemWatcher
{
public:
 enum Filter
 {
  FILTER_FILE_NAME        = 0x00000001, // add/remove/rename
  FILTER_DIR_NAME         = 0x00000002, // add/remove/rename
  FILTER_ATTR_NAME        = 0x00000004,
  FILTER_SIZE_NAME        = 0x00000008,
  FILTER_LAST_WRITE_NAME  = 0x00000010, // timestamp
  FILTER_LAST_ACCESS_NAME = 0x00000020, // timestamp
  FILTER_CREATION_NAME    = 0x00000040, // timestamp
  FILTER_SECURITY_NAME    = 0x00000100
 };
 enum ACTION
 {
  ACTION_ERRSTOP          = -1,
  ACTION_ADDED            = 0x00000001,
  ACTION_REMOVED          = 0x00000002,
  ACTION_MODIFIED         = 0x00000003,
  ACTION_RENAMED_OLD      = 0x00000004,
  ACTION_RENAMED_NEW      = 0x00000005
 };

 typedef void (__stdcall *LPDEALFUNCTION)( ACTION act, LPCWSTR filename, LPVOID lParam );

 FileSystemWatcher();
 ~FileSystemWatcher();

 // LPCTSTR dir: ended-with "\\"
 bool Run( LPCTSTR dir, bool bWatchSubtree, DWORD dwNotifyFilter, LPDEALFUNCTION dealfun, LPVOID lParam );
 void Close( DWORD dwMilliseconds=INFINITE );

private: // no-impl
 FileSystemWatcher( const FileSystemWatcher& );
 FileSystemWatcher operator

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值