How to use FILE_ACTION_REMOVED ??

How to use FILE_ACTION_REMOVED ??

Post by zdk » Sat, 29 Jul 2006 18:27:56


've the code below... and I need to check when a file is created do
the FTP and when a file is removed then don't do anything.But I have no
way to check fni->Action correctly.

Any help or suggest would be greatly appreciated much.
Thanks a lot.


#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>

char uploader[]="C:\\Uploader\\ncftpput.exe -R -U 22 ";
char usrpass[]="-u www-data -p secret 43.72.1.31 ";
void RefreshDirectory(LPTSTR);
void RefreshTree(LPTSTR);

void WatchDirectory(LPTSTR lpDir)
{
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
TCHAR lpDrive[4];
TCHAR lpFile[_MAX_FNAME];
TCHAR lpExt[_MAX_EXT];
PFILE_NOTIFY_INFORMATION fni;
char Buffer[100];
fni=(PFILE_NOTIFY_INFORMATION) Buffer;


_tsplitpath(lpDir, lpDrive, NULL, lpFile, lpExt);

lpDrive[2] = (TCHAR)'\\';
lpDrive[3] = (TCHAR)'\0';

strcat(uploader,lpDir);

// Watch the directory for file creation and deletion.

dwChangeHandles[0] = FindFirstChangeNotification(
lpDir, // directory to watch
FALSE, // do not watch subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes

if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());

// Watch the subtree for directory creation and deletion.

dwChangeHandles[1] = FindFirstChangeNotification(
lpDrive, // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir. name changes

if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());

// Change notification is set. Now wait on both notification
// handles and refresh accordingly.

while (TRUE)
{
// Wait for notification.

dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);

switch (dwWaitStatus)
{
case WAIT_OBJECT_0:

// A file was created or deleted in the directory.
// Refresh this directory and restart the notification.
printf("action: %d \n",fni->Action);
switch(fni->Action){

case FILE_ACTION_ADDED:
printf("ADD \n");
break;

case FILE_ACTION_REMOVED:
printf("REMOVED \n");
break;

}
RefreshDirectory(lpDir);
if ( FindNextChangeNotification(
dwChangeHandles[0]) == FALSE )
ExitProcess(GetLastError());
break;

case WAIT_OBJECT_0 + 1:

// A directory was created or deleted in the subtree.
// Refresh the tree and restart the notification.

RefreshTree(lpDrive);
if (FindNextChangeNotification(
dwChangeHandles[1]) == FALSE)
ExitProcess(GetLastError());
break;

default:
ExitProcess(GetLastError());
}
}
}

void RefreshDirectory(LPTSTR lpDir)
{
//_tprintf(TEXT("Refresh the directory (%s).\n"), lpDir)
_tprintf(TEXT("Refresh the directory (%s).\n"), uploader);
//int iReturn = (int) ShellExecute(NULL, "open", , NULL, NULL,
SW_SHOWNORMAL);
//if (iReturn > 32){ delete }

}

void RefreshTree(LPTSTR lpDrive)
{
//_tprintf(TEXT("Refresh the directory tree (%s).\n"), lpDrive);
//int iReturn = (int) ShellExecute(NULL,