How to use FILE_ACTION_REMOVED ??

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'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, "open", , NULL, NULL,
SW_SHOWNORMAL);
_tprintf(TEXT("Refresh the directory tree(%s).\n"), uploader);
}

int main(int argc, char *argv[])
{
strcat(uploader, usrpass);
WatchDirectory(argv[1]);
}

.



Relevant Pages

  • Re: inhibit compiler warning C4624 for a class hierarchy
    ... I'd really like to just pretend that the dynamic type is the base class. ... ** Carries a request or notification and any associated parameters. ... static void* operator new ... struct PNPEXPORT IConcurrentOperations::OpNotification abstract: public ...
    (microsoft.public.vc.language)
  • Re: Mobile Service & Auto Start
    ... just very dumb about the CeRunAppAtTime call and why it may not work. ... /// This Notification sample uses the Notification Manager in Windows ... private OpenNETCF.Windows.Forms.GroupBox groupBox1; ... private void InitializeComponent() ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Mobile Service & Auto Start
    ... Check the Notify class. ... /// This Notification sample uses the Notification Manager in Windows CE.NET ... private OpenNETCF.Windows.Forms.GroupBox groupBox1; ... private void InitializeComponent() ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: SQLDependency breaks after losing database connection
    ... We refresh the cache (re-execute the ... query) and reregister the notification when the database connection is ... After the database connection is restored, ...
    (microsoft.public.sqlserver.programming)
  • Re: Mobile Service & Auto Start
    ... Check the Notify class. ... /// This Notification sample uses the Notification Manager in Windows CE.NET ... private OpenNETCF.Windows.Forms.GroupBox groupBox1; ... private void InitializeComponent() ...
    (microsoft.public.dotnet.framework.compactframework)