Click to See Complete Forum and Search --> : how can i monitor a folder


michael1975
April 8th, 2001, 07:06 AM
Hei,
I want to monitor a Folder, that means if there is any new file is
stored here, i can automatically know precisely these new files name, but i
do not want know the by monitor detect the Directory disk size and then
compare all the files names way, because i donot want to maintain a files
list always. Does anybody knows is there any event can be detected when the
folder is added a new file?
My question is:
There is a directory named ImageFile,
and i want to write a program to monitor it always,
and if a file Image1 is added into ImageFile folder by anybody, i can know
it precisely and immediately, but i do not want to scan all the files in
this folder, because maybe there are a huge number of files.
Can i do it, and how?

Many thanks.

Michael.

Email: xiaosd1975@sina.com



a free codes guru

John G Duffy
April 8th, 2001, 07:32 AM
You might play with this a bit

private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4
private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2
private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
private Const FILE_NOTIFY_CHANGE_SIZE = &H8
private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10
private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100
private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (byval lpPathName as string, byval bWatchSubtree as Long, byval dwNotifyFilter as Long) as Long
private Declare Function FindCloseChangeNotification Lib "kernel32" (byval hChangeHandle as Long) as Long
private Declare Function FindNextChangeNotification Lib "kernel32" (byval hChangeHandle as Long) as Long
private Declare Function WaitForSingleObject Lib "kernel32" (byval hHandle as Long, byval dwMilliseconds as Long) as Long
private Declare Function ResetEvent Lib "kernel32" (byval hEvent as Long) as Long
private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret as Long
'set the notification hook
Ret = FindFirstChangeNotification("C:\", &HFFFFFFFF, FILE_NOTIFY_CHANGE_ALL)
'Wait until the event is triggered
WaitForSingleObject Ret, &HFFFFFFFF
MsgBox "Event Triggered for the first time"
'Reactivate our hook
FindNextChangeNotification Ret
'Wait until the event is triggered
WaitForSingleObject Ret, &HFFFFFFFF
MsgBox "Event Triggered for the second time"
'Remove our hook
FindCloseChangeNotification Ret
End Sub





John G

Iouri
April 9th, 2001, 07:25 AM
Hi John,
I love this code. Get the rating from me.

Iouri Boutchkine
iouri@hotsheet.com

Cimperiali
April 9th, 2001, 09:20 AM
Great code. Tomorrow I will rate you!

Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.

Cimperiali
April 11th, 2001, 02:23 AM
Now I can rate you!

Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.