Dark_dance

取次花丛懒回首,半缘修道半缘君

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ReadDirectoryChangesW 函数

对指定的目录进行监控,返回详细的文件变化信息。

函数形式

01 BOOL WINAPI ReadDirectoryChangesW(
02 
__in         HANDLE hDirectory,   // 对目录进行监视的句柄
03
 __out        LPVOID lpBuffer,     // 一个指向DWORD类型的缓冲区,其中可以将获取的数据结果将其返回。
04
 __in         DWORD nBufferLength, // 指lpBuffer的缓冲区的大小值,以字节为单位。
05 
__in         BOOL bWatchSubtree, // 监视目录. 一般选择 TRUE
06 
__in         DWORD dwNotifyFilter, // 对文件过滤的方式和标准
07 
__out_opt    LPDWORD lpBytesReturned, // 将接收的字节数转入lpBuffer参数
08 
__inout_opt LPOVERLAPPED lpOverlapped, // 一般选择 NULL
09 
__in_opt     LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // 一般选择 NULL
10 );

1.hDirectory [中]

       This directory must be opened with the FILE_LIST_DIRECTORY access right.
       被监视的目录必须打开FILE_LIST_DIRECTORY的访问权限
       
2.lpBuffer[中]

       The structure of this buffer is defined by the FILE_NOTIFY_INFORMATION structure
       这个缓冲区的定义是FILE_NOTIFY_INFORMATION结构。
       This buffer is filled either synchronously or asynchronously, 
       depending on how the directory is opened and what value is given to the lpOverlapped parameter.
       这个缓冲区充满要么同步或异步,这取决于如何打开目录什么价值给予lpOverlapped参数。

3.nBufferLength [中] 
       
       The size of the buffer that is pointed to by the lpBuffer parameter, in bytes.
       大小的缓冲区,是指出的lpBuffer参数,以字节为单位。

4.bWatchSubtree [中]

       If this parameter is TRUE, the function monitors the directory tree rooted at the specified directory.
       如果这个参数是TRUE,那么这个函数会监视目录树,所指定的当前的根目录(整个路径信息都显示出来)。

       If this parameter is FALSE, the function monitors only the directory specified by the hDirectory parameter.
       如果这个参数是FALSE ,则函数则只监视hDirectory句柄所指定的目录下的内容(只显示出发生变化的文件目录)。 
       
5.dwNotifyFilter [中]

       The filter criteria that the function checks to determine if the wait operation has completed.
       该过滤器的标准,功能检查,以决定是否等待操作完成。 
       This parameter can be one or more of the following values.这个参数可以是一个或多个下列值。 
         
      【FILE_NOTIFY_CHANGE_FILE_NAME】 0x00000001
       Any file name change in the watched directory or subtree causes a change notification wait operation to return.
       任何文件名改变 都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。 
       Changes include renaming, creating, or deleting a file.
       变化包括重命名,创建或删除文件。 

      【FILE_NOTIFY_CHANGE_DIR_NAME】 0x00000002 
       Any directory-name change in the watched directory or subtree causes a change notification wait operation to return.
       任何目录名称改变 都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。
       Changes include creating or deleting a directory.
       改变包括建立或删除一个目录。 

      【FILE_NOTIFY_CHANGE_ATTRIBUTES】 0x00000004 
       Any attribute change in the watched directory or subtree causes a change notification wait operation to return.
       任何属性变化,都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。

      【FILE_NOTIFY_CHANGE_SIZE】 0x00000008 
       Any file-size change in the watched directory or subtree causes a change notification wait operation to return.
       任何文件大小的变化,都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。 
       The operating system detects a change in file size only when the file is written to the disk.
       操作系统检测改变文件大小,只有当该文件被写入到磁盘时发生。 
       For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
       操作系统使用广泛缓存,检测时才会发生的缓存足够同满。

      【FILE_NOTIFY_CHANGE_LAST_WRITE】0x00000010 
       Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return.
       任何改变过去修改时间的文件 ,都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。
       The operating system detects a change to the last write-time only when the file is written to the disk.
       操作系统检测改变过去写的时间只有当该文件被写入到磁盘。 
       For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
       操作系统使用广泛缓存,检测时才会发生的缓存足够同满。 

      【FILE_NOTIFY_CHANGE_LAST_ACCESS】0x00000020 
       Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
       任何改变文件最近访问时间,都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。

      【FILE_NOTIFY_CHANGE_CREATION】 0x00000040 
       Any change to the creation time of files in the watched directory or subtree causes a change notification wait operation to return.
       任何改变文件的创建时间的,都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。

      【FILE_NOTIFY_CHANGE_SECURITY】0x00000100 
       Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.
       任何安全描述符被改变的,都会查看所在目录或子目录的变更,并将结果通知给等待操作返回。

6.lpBytesReturned [了,可选] 

       For synchronous calls, this parameter receives the number of bytes transferred into the lpBuffer parameter.
       同步调用,这个参数接收的字节数转入lpBuffer参数。 
       For asynchronous calls, this parameter is undefined.
       异步调用,这个参数是未定义的。 
       You must use an asynchronous notification technique to retrieve the number of bytes transferred.
       您必须使用异步通知技术检索的字节数转移。

7.lpOverlapped [中,那样,可选] 
        
       A pointer to an OVERLAPPED structure that supplies data to be used during asynchronous operation.
       一个指针的重叠结构,提供供数据时使用的异步操作。 
       
       Otherwise, this value is NULL.
       否则,这个值为NULL 。 
       
       The Offset and OffsetHigh members of this structure are not used. 
       OFFSET和OffsetHigh成员结构不使用。

8.lpCompletionRoutine [中,可选] 

 

       A pointer to a completion routine to be called when the operation has been completed or canceled and the calling 
       thread is in an alertable wait state.
       一个指针一个完成例程 如果在呼叫使用函数操作时已经完成或取消和调用线程是在alertable等待状态。
       
返回值

       If the function succeeds, the return value is nonzero.
       如果函数成功,返回值为非零。

       For synchronous calls, this means that the operation succeeded.
       同步要求,这意味着操作取得了成功。

       For asynchronous calls, this indicates that the operation was successfully queued.
       异步调用,这表明操作成功排队。

If the function fails, the return value is zero.
如果函数失败,返回值是零。

To get extended error information, call GetLastError .
要获得扩展错误信息,请用GetLastError返回错误 。

If the network redirector or the target file system does not support this operation, the function fails with ERROR_INVALID_FUNCTION.
如果网络重定向或目标文件系统不支持这一行动,该功能失败, ERROR_INVALID_FUNCTION 。

hat the operation succeeded.
       同步要求,这意味着操作取得了成功。

       For asynchronous calls, this indicates that the operation was successfully queued.
       异步调用,这表明操作成功排队。

If the function fails, the return value is zero.
如果函数失败,返回值是零。

To get extended error information, call GetLastError .
要获得扩展错误信息,请用GetLastError返回错误 。

If the network redirector or the target file system does not support this operation, the function fails with ERROR_INVALID_FUNCTION.
如果网络重定向或目标文件系统不支持这一行动,该功能失败, ERROR_INVALID_FUNCTION 。

posted on 2011-12-01 14:36  流沙-  阅读(1791)  评论(0编辑  收藏  举报