|
-
July 11th, 2005, 06:48 AM
#1
Multiple Files with ReadDirectoryChangesW
Apologies for starting another thread on this function (and posting it in this thread, should've really gone in the Visual C++ thread...) but I'm having a problem picking up multiple files copied to a watched directory.
I have a watched directory which is picking up single files perfectly fine. However, when I drop 2 or more files into the directory, I am only able to pick up the 1st file.
My current code is as follows:
HTML Code:
UINT CMyAppDlg::ReadDirChangesThread(LPVOID lpData)
{
AFX_MANAGE_STATE(AfxGetModuleState());
USES_CONVERSION;
OutputThreadDebug("Directory Changes Thread Started...");
CString csFilename = "";
ThreadData *pData = (ThreadData*) lpData;
HANDLE hDir = ::CreateFile(pData->csDirectory, FILE_LIST_DIRECTORY, FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);
ASSERT(hDir != INVALID_HANDLE_VALUE);
FILE_NOTIFY_INFORMATION Buffer[512];
memset((void*)&Buffer,0,sizeof(Buffer));
DWORD dwBytesReturned;
BOOL bFound = FALSE;
do
{
if (ReadDirectoryChangesW(hDir,&Buffer,
sizeof(Buffer),
FALSE,
FILE_NOTIFY_CHANGE_FILE_NAME,
&dwBytesReturned,
NULL,
NULL))
{
csFilename = (CString(Buffer[0].FileName).Left(Buffer[0].FileNameLength / 2));
// Do something with the filename
}
// Post a message to the calling thread indicating that we've finished
::PostMessage(pData->ParenthWnd,UWM_THREAD_FINSHED,0,0);
::OutputDebugString("Thread finished\n");
}
I know this will only ever pick up one filename, but I was hoping there would be a nice easy way to modify this to pick up multiple filenames and add them to thread safe array maybe?
Or would it be easier to run this in asynchronous mode? Or am I doing this compeltely wrong?!
Last edited by NotBad; July 11th, 2005 at 07:14 AM.
Reason: Changed some function names to hide the real app I'm working on!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|