Am I doing this right?
I am trying to find all the changes that took place in a folder called C:\Perl
After ReadDirectoryChangesW, it just gets stuck there. It doesn't move forward. Am I missing something obvious?
I am trying to achieve: How can I detect only deleted, changed, and created files on a volume?
Once everyday, I want to run the backup program, which will backup only the files that were changed under a specific folder.
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szBuffer[640] = {0};
DWORD dwOffset = 0;
FILE_NOTIFY_INFORMATION* pInfo = NULL;
DWORD dwBytes;
HANDLE hFolder = CreateFile(L"C:\\Perl", FILE_LIST_DIRECTORY, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
cout<<"Hello"<<endl;
ReadDirectoryChangesW(hFolder, szBuffer, sizeof(szBuffer) / sizeof(TCHAR), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME, &dwBytes, NULL, NULL);
cout<<"Done"<<endl;
do
{
// Get a pointer to the first change record...
pInfo = (FILE_NOTIFY_INFORMATION*) &szBuffer[dwOffset];
// ReadDirectoryChangesW processes filenames in Unicode. We will convert them to a TCHAR format...
TCHAR szFileName[MAX_PATH] = {0};
wcout<<pInfo->FileName<<"\t"<<pInfo->Action ;
//WideCharToMultiByte(CP_ACP, NULL, pInfo->FileName, pInfo->FileNameLength, szFileName, sizeof(szFileName) / sizeof(TCHAR), NULL, NULL);
// Perform your tests here...
if (pInfo->Action == FILE_ACTION_ADDED)
{
}
// More than one change may happen at the same time. Load the next change and continue...
dwOffset += pInfo->NextEntryOffset;
}
while (pInfo->NextEntryOffset != 0);
}