全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2858
推到 Plurk!
推到 Facebook!

如何監控某個目錄下的檔案異動...?

尚未結案
kensoong
初階會員


發表:31
回覆:70
積分:45
註冊:2003-05-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-11 01:24:15 IP:211.74.xxx.xxx 未訂閱
請教各位高手: 在Win32平台上如何去監控某一個folder下的檔案異動情形,如 Add new file, Update an old file,甚至Delete files...等呢? Return值:須傳回異動的檔名,與其Action/Status. 有這種Win32 API嗎? 謝謝各位...
supman
尊榮會員


發表:29
回覆:770
積分:924
註冊:2002-04-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-11 02:18:27 IP:203.204.xxx.xxx 未訂閱
您好: 以下這一篇您參考一下 http://bdn.borland.com/article/0,1410,21743,00.html
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-11 08:36:56 IP:61.222.xxx.xxx 未訂閱
Copy Hook 或同上 監視資料夾異動情形。
mind9sky
一般會員


發表:1
回覆:4
積分:1
註冊:2003-04-03

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-04-13 16:56:18 IP:210.63.xxx.xxx 未訂閱
可試試看改寫樓上大大提供的資料中的TActiveListBox::PopulateFileList() 利用ReadDirectoryChangesW來得到FIND_NOTIFY_INFORMATION . 原諒我不會bcb,只能用口頭講講 void __fastcall TActiveListBox::PopulateFileList() //fill list box w/ files { TSearchRec sr; Items->Clear(); if (FPath == "") return; FindFirst(FPath "*.*",faAnyFile,sr); do { Items->Add(sr.Name); } while (!FindNext(sr)); FindClose(sr); } 這是win SDK的說明 The FIND_NOTIFY_INFORMATION structure describes the changes found by the ReadDirectoryChangesW function. typedef struct _FILE_NOTIFY_INFORMATION { DWORD NextEntryOffset; DWORD Action; DWORD FileNameLength; WCHAR FileName[1]; } FILE_NOTIFY_INFORMATION; The ReadDirectoryChangesW function returns information describing the changes occurring within a directory. BOOL ReadDirectoryChangesW( HANDLE hDirectory, // handle to the directory to be watched LPVOID lpBuffer, // pointer to the buffer to receive the read results DWORD nBufferLength, // length of lpBuffer BOOL bWatchSubtree, // flag for monitoring directory or directory tree DWORD dwNotifyFilter, // filter conditions to watch for LPDWORD lpBytesReturned, // number of bytes returned LPOVERLAPPED lpOverlapped, // pointer to structure needed for overlapped I/O LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // pointer to completion routine );
kensoong
初階會員


發表:31
回覆:70
積分:45
註冊:2003-05-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-04-17 08:09:27 IP:211.74.xxx.xxx 未訂閱
感謝各位的協助... 範例是c multi-thread寫法較難要改成Delphi不是那麼容易? 而copy hook可以做得到嗎?! Sorry,最近很忙,加班把企業重要的Oracle 9i搞定而已,還在研究中...
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-04-18 20:40:45 IP:61.31.xxx.xxx 未訂閱
事實上 supman 所提供的,試著將 C to Delphi 程式碼不會很複雜。 順便可以瞭解一下。 有一元件可做到。用Thread 配合FindFirstChangeNotification 及 FindNextChangeNotification 可在此下載(含 Source) http://www.sources.ru/delphi/DirWatcher.zip 網頁連結 http://www.delphimaster.ru/cgi-bin/faq.pl?look=1&id=15-988621361
系統時間:2024-05-03 12:29:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!