📄 subject_29654.htm
字号:
<p>
序号:29654 发表者:worm 发表日期:2003-02-11 02:04:35
<br>主题:如何监视某个文件夹中的文件状态?
<br>内容:如此文件夹中是否有文件正在写入,或文件是否正被改写等。
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:bb 回复日期:2003-02-11 09:05:10
<br>内容:方法一<BR>Monitoring Changes in a Directory or Directory Tree<BR><BR>The following example monitors the directory tree starting at C:\ for directory name changes. It also monitors the C:\WINDOWS directory for file name changes. <BR><BR>The example uses the FindFirstChangeNotification function to create two notification handles and the WaitForMultipleObjects function to wait on the handles. Whenever a directory is created or deleted in the tree starting at C:\ , the example updates the entire directory tree. Whenever a file is created or deleted in the C:\WINDOWS directory, the example refreshes the WINDOWS directory. The FindNextChangeNotification function restarts the change notification each time the example processes a change. <BR><BR>DWORD dwWaitStatus; <BR>HANDLE dwChangeHandles[2]; <BR> <BR>// Watch the C:\WINDOWS directory for file creation and <BR>// deletion. <BR> <BR>dwChangeHandles[0] = FindFirstChangeNotification( <BR> "C:\\WINDOWS", // directory to watch <BR> FALSE, // do not watch the subtree <BR> FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes <BR> <BR>if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) <BR> ExitProcess(GetLastError()); <BR> <BR>// Watch the C:\ subtree for directory creation and <BR>// deletion. <BR> <BR>dwChangeHandles[1] = FindFirstChangeNotification( <BR> "C:\\", // directory to watch <BR> TRUE, // watch the subtree <BR> FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes <BR> <BR>if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) <BR> ExitProcess(GetLastError()); <BR> <BR>// Change notification is set. Now wait on both notification <BR>// handles and refresh accordingly. <BR> <BR>while (TRUE) <BR>{ <BR> <BR> // Wait for notification.<BR> <BR> dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, <BR> FALSE, INFINITE); <BR> <BR> switch (dwWaitStatus) <BR> { <BR> case WAIT_OBJECT_0: <BR> <BR> // A file was created or deleted in C:\WINDOWS. <BR> // Refresh this directory and restart the <BR> // change notification. RefreshDirectory is an <BR> // application-defined function. <BR> <BR> RefreshDirectory("C:\\WINDOWS") <BR> if ( FindNextChangeNotification( <BR> dwChangeHandles[0]) == FALSE ) <BR> ExitProcess(GetLastError()); <BR> break; <BR> <BR> case WAIT_OBJECT_0 + 1: <BR> <BR> // A directory was created or deleted in C:\. <BR> // Refresh the directory tree and restart the <BR> // change notification. RefreshTree is an <BR> // application-defined function. <BR> <BR> RefreshTree("C:\\"); <BR> if (FindNextChangeNotification( <BR> dwChangeHandles[1]) == FALSE) <BR> ExitProcess(GetLastError()); <BR> break; <BR> <BR> default: <BR> ExitProcess(GetLastError()); <BR> } <BR>} <BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bb 回复日期:2003-02-11 09:10:10
<br>内容:方法二<BR><BR>Windows NT 3.5+sp3以上(win95/98不支持)<BR><BR>BOOL ReadDirectoryChangesW(<BR> HANDLE hDirectory, // handle to directory<BR> LPVOID lpBuffer, // read results buffer<BR> DWORD nBufferLength, // length of buffer<BR> BOOL bWatchSubtree, // monitoring option<BR> DWORD dwNotifyFilter, // filter conditions<BR> LPDWORD lpBytesReturned, // bytes returned<BR> LPOVERLAPPED lpOverlapped, // overlapped buffer<BR> LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // completion routine<BR>);<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -