如何監控某個目錄下的檔案異動...? |
尚未結案
|
kensoong
初階會員 發表:31 回覆:70 積分:45 註冊:2003-05-28 發送簡訊給我 |
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
mind9sky
一般會員 發表:1 回覆:4 積分:1 註冊:2003-04-03 發送簡訊給我 |
可試試看改寫樓上大大提供的資料中的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 發送簡訊給我 |
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
事實上 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
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |