help on monitor the folder
Hi, guru,
I'm a VC beginner and now building a FTP client.
I want to build a programme to monitor the folder like "d:\temp". If a new file is created on the folder, the ftp it to the server.
My question is:
what event or function I need to check there is a new file created on the folder?
rgds,
the question in programme
Hi, friend,
Thanks for the reply.
I look up some sample of MS and try to use it. But there is a dead loop.
I build the function:
OnButtonClick()
{
function1();
function2();
}
The function1() is OK. For function2():
void function2()
{
DWORD dwWaitStatus;
HANDLE dwChangeHandles;
// Watch the m_strMonitorFolderName directory for file creation
dwChangeHandles = FindFirstChangeNotification(
m_strMonitorFolderName, // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
if (dwChangeHandles == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());
while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForSingleObject( dwChangeHandles, 0);
if(dwWaitStatus==WAIT_OBJECT_0)
{
function3();
if ( FindNextChangeNotification( dwChangeHandles) == FALSE )
ExitProcess(GetLastError());
}
}
Question:
1. Because I want the programme monitor the folder after strat up, so I use while(true) in function2. But there seems the programme is dead lock after call function2.
2. I want to monitor whether there is a new file created, is that right to use
dwChangeHandles = FindFirstChangeNotification(
m_strMonitorFolderName, // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
3. I want to programme react immediatly, so whether it is right to use
dwWaitStatus = WaitForSingleObject( dwChangeHandles, 0);
cheers!