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

如何監控一個文件目錄中的新建,刪除,修改等操作!

答題得分者是:bugmans
netplaier
一般會員


發表:1
回覆:1
積分:0
註冊:2007-08-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-01-27 21:19:11 IP:123.14.xxx.xxx 訂閱
Delphi自帶的ShellChangeNotifier檢測控件可以對目錄如創建,修改,刪除等操作的監控。
但是對臨時文件夾(rfTemplates)就不能判斷出具體創建的對象了,怎麽回事,這方面怎麽解決???
我想對臨時文件夾中的一些特定類型的文件進行監控操作,請問還有沒有其它方法,搜了一些資料,說通過API到可以(在WIN32下用DELPHI偵測目錄變化,可用WIN32提供的文件改變通知API來完成。FindFirstChangeNotification, FindNextChangeNotification,FindCloseChangeNotification。
),具體怎麽實現???
編輯記錄
netplaier 重新編輯於 2008-01-27 21:19:51, 註解 無‧
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-01-28 11:16:15 IP:210.69.xxx.xxx 訂閱
考慮看看用 HOOK API 攔截建立目錄的 API
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-01-28 13:42:49 IP:122.127.xxx.xxx 訂閱
------
努力會更接近成功
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-01-28 13:48:41 IP:122.127.xxx.xxx 訂閱
除了元件, 也可以研究Source Code

ATFileNotification v.1.1.3FWS317 k31 Mar 2007
By Alexey Torgashin. ATFileNotification is improved version of fisFileNotification component (which was originally written by FIS House). It allows to watch for files/directories changes and to fire an event when change occurs. Improvements are:
  • Component made Unicode compatible;
  • FileName property added: you can watch for changes in a single file;
  • Attempt to make component thread-safe (need feedback about it).
Fully functional Source: Included Exe-Demo Included
Download: CB2k6 CB5 CB6 D2005 D2006 D5 D6 D7 Homepage

Alfa File Monitor Network Edition v.2004C945 k06 May 2004
By Alfa Corporation. Alfa File Monitor (AFM) is a Delphi component designed for real-time file monitoring. The Lite version of AFM monitors Create, Rename and Delete events (files and directories fire separate events), whereas the Full version monitors all file events, including Read, Write, Flush, Close, Attribute Query, Attribute Change, Time Set, Time Change - in other words all file events You would need. AFM Supports Windows 95/ 98/ 98SE/ Me/ NT4/ 2000/ XP/ 2003. Note: The demo version will work 3 months after download. After that date it should be removed from the system. Evaluation (time-limit) Source: On purchase/registration Price: $1999.95 Exe-Demo Included
Download: CB3 CB4 CB5 CB6 D3 D4 D5 D6 D7 Gift for Torry. Thank You !Register NowHomepage

DCNotify v.1.00FWS8 k23 May 1997
By Andrew Venmore. TDiskChangeNotify and TDiskChangeNotifyEx are two components that provide notification if any changes have taken place in a folder e.g. Files added/ deleted/ size or attributes changed. Fully functional Source: Included
Download: D2

DirMonitor v.1.2FWS264 k03 Dec 2002
By Juan Carlos Molinos. This is a Windows API based component for monitoring any changes in specified local or remote folder. Unless other Directory Monitors, this one doesn't lose events, even remote. Monitored Events:
  • File/Folder Creation, Modify, Change, Deletion, Rename.
  • Security changes.
  • A single notification for every event.
  • Subdirectory notification.
  • The event receives the Path File Name affected and selected Action.
Fully functional Source: Included Exe-Demo Included
Download: D6

Direcory Changes Monitoring Component v.1.0FWS8 k06 Nov 2000
By Phaeteon. Direcory Changes Monitoring Component. You will be notified by all inserted, deleted, modified and renamed files or subdirs in a directory. It runs only under NT Plattforms. Fully functional Source: Included
Download: D4 D5 Homepage

Disc Drive Monitor v.1.02FWS7 k04 Feb 1998
By Grahame Marsh. A TThread class descendant to notify of changes to files and subdirectories. It encapsulates the FindFirstChangeNotification API. Includes a component wrapper for installation on the palette. Requires TBrowseDirectory component. Fully functional Source: Included
Download: D2 D3

ShellNotify v.1FNCS6 k24 Jun 2005
By Federico Firenze. A non-visual componet to catch some undocumented FileSystem events. Such as:
  • File type association has changes;
  • File attributes changes;
  • A non-folder item creation / deletion / rename;
  • A non-folder item deletion;
  • Drive insertion / removed;
  • Drive insertion and the Shell should create a new window for the drive;
  • Storage media has been inserted / removed;
  • Folder Creation / Deletion / Renamed;
  • Folder Sharings / Unsharing;
  • Network Disconnection;
  • The contents of an existing folder changes;
  • An image in the system image list changes;
  • An existing nonfolder item changes, but the item still exists and has not been renamed.
Fully functional Source: Included Exe-Demo Included
Download: D1 D2 D3 D4 D5 D6 D7 Homepage

TDirChange v.1.1FWS22 k18 Aug 1998
By Tomasz Kustra. Small component for monitoring directory changes. Now monitors subdirectories. Fully functional Source: Included
Download: D2 D3

TDirMon v.1.00FWS10 k24 Feb 1998
By Francois Piette. This component encapsulate the Win 32 API function FindFirst ChangeNotification. The primary purpose of this component is to monitor changes in a given directory and fire an event when a change occurs (file creation, deletion, etc). Fully functional Source: Included
Download: D2 D3 Homepage

TFnugry DirWatch v.1.0FWS99 k16 Dec 1998
By Gleb Yourchenko. FnugryDirWatch component wraps the ReadDirectoryChangesW API (NT Only) function that allows applications to respond to changes in the file system, such as new file and/or directory creation, renaming, size, attribute, and time changes, etc. Fully functional Source: Included
Download: D3

TFnugry FileNotify v.1.01FWS74 k16 Dec 1998
By Gleb Yourchenko. TFnugryFileNotify component encapsulates FindXXXXChangeNotification API routines, and can be used to trace file system changes, including file or folder creation, change, access, or deletion. Fully functional Source: Included
Download: D3

TGFGLWatch FilesForDelete v.0.1FWS9 k05 Oct 1998
By Greg Lorriman. Watched individual files for deletion or move using low priority threads. Better feedback than from windows notification API calls when tracking deletions. Fully functional Source: Included
Download: D2 D3 Homepage

TOxygenDirectorySpy v.1.7SW315 k15 Aug 2006
By Oxygen Software. TOxygenDirectorySpy component allows you to watch file system changes including file or directory creation, access, removing, changing size and attributes. The heart of this component is in that unlike plenty of similar tools, it returns the precise name of a directory or a file having been changed, along with former and current values of changed parameters. You can watch file system changes even on network drives. Now you can monitor multiple directories including their subdirectories. Note: Monitoring subdirectories is not supported by Windows 95/98. If you need it, you should add all these directories manually to Directories property. With Nag-Screen Source: On purchase/registration Price: $25
Download: D2005 D2006 D3 D4 D5 D6 D7 Register NowHomepage

TSHChangeNotify v.3.0FWS24 k12 Oct 2000
By Elliott Shevin. TSHChangeNotify traps certain events in the system and invokes a event handler in your program when the corresponding event occurs, passing information relating to the event. Examples of events and what you receive are: CD inserted or removed (the path of the CD drive); file renamed or moved (before and after path and file names. Fully functional Source: Included
Download: D2 D3 D4 D5

TfisFile Notification v.1.00FWS5 k04 Aug 2000
By First Internet Software House. This non-visual component monitors the contents of a directory or directory tree. Many different file changes can be monitored such as file size, last write, creation & deletion etc. An event is triggered when these occurs. Fully functional Source: Included
Download: CB3 CB4 D2 D3 D4 D5
------
努力會更接近成功
bugmans
高階會員


發表:95
回覆:322
積分:188
註冊:2003-04-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-01-28 18:40:03 IP:125.224.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=49776
我曾為了這篇討論而去研究ATFileNotification原始碼,我也將所得心得紀錄下來
只是覺得自己文筆不怎麼好,怎麼寫還是有不通順的地方,只完成一半就停止了
下載位置:
http://delphi.ktop.com.tw/download.php?download=upload/479da8813c1fc_FileNotification.rar
netplaier
一般會員


發表:1
回覆:1
積分:0
註冊:2007-08-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-01-29 14:22:43 IP:123.14.xxx.xxx 訂閱
感謝樓上的幾位答案,的確可監控文件,新建,刪除,修改等操作!與Delphi 7工具面板中Samples頁自帶的ShellChangeNotifier控件的性質與使用方法上基本類似,

在獲取操作對象的路徑(如新建一個文件)上,如何正確讀取其路徑呢??
Delphi自帶的 ShellChangeNotifier使用DEMO可以看這,完全可实现上述FileNotification第三插件的功能。
http://www.delphibbs.com/keylife/iblog_show.asp?xid=4265


-------------------------------------------------------------------------------

對與上述所講到對過HOOK API進行操作,不知有具體實例沒??
編輯記錄
netplaier 重新編輯於 2008-01-29 14:24:07, 註解 無‧
netplaier 重新編輯於 2008-01-29 14:30:30, 註解 無‧
change.jian
版主


發表:29
回覆:620
積分:439
註冊:2003-06-02

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-02-26 14:24:09 IP:211.23.xxx.xxx 訂閱
1.理論上,上述的回覆及您所提的方法,都可以監看到檔案或目錄的變更.您所謂不能監看,小弟大膽猜測應該是程式那裡有 bug 才是.
2.依您的需求,不建議您去使用 Hook API 的技術來做,理由很簡單:吃力不討好.
(1)必需先完成所有改變檔案/目錄的 API hook 才行,換言之,您得把所有相關的 API 都 HOOK 到....很累的.
(2)由於要 Hook 的對象是不定對象,換言之,您必需要想辦法讓您的 dll (HOOK API) inject 到其他的 process 之後還能不弄掛那些 process,這個並不容易.
(3)若真的要很穩的監控,建議您朝 driver 著手, google 一下 filemon 關鍵字,應該可以找到不少資料
(4)若想要 HOOK API 的資料,可以 google 一下 RootKit 這個字,應該也可以找到你要的東西

PS:補充一下,在 VS 2003 /2005 上有您要的元件,叫 FileSystemWatch 的,您也可以參考看看
編輯記錄
change.jian 重新編輯於 2008-02-26 14:25:36, 註解 無‧
terrygobb
一般會員


發表:5
回覆:22
積分:5
註冊:2009-04-27

發送簡訊給我
#8 引用回覆 回覆 發表時間:2009-05-13 09:28:18 IP:220.130.xxx.xxx 訂閱
受教嚕~~感謝分享~~

研讀中~
------
尋找對的人,對的方法,對的態度跟對的環境
系統時間:2024-11-21 21:55:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!