asked on
sprintf(msgbuf, "Cannot open file %s [err=%ld]\n", lpExistingFileName, GetLastError());
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
#include "stdafx.h"
#include "stdio.h"
#include "WinBase.h"
#include "Windows.h"
int CheckFiles()
{
DWORD dwWaitStatus;
HANDLE dwChangeHandle;
BOOL fFinished = FALSE;
char SourceDir[100];
int Times=0,FailureCount=0;
char Inipath2[255];
TCHAR szBuffer[640] = {0};
DWORD dwOffset = 0;
FILE_NOTIFY_INFORMATION* pInfo = NULL;
DWORD dwBytes;
//Configuration file
strcpy(Inipath2, "f:\\tracsdata\\admin.ini");
//Source Directory
GetPrivateProfileString("LOAD","MAINDIR","f:\\product\\beta\\",SourceDir,sizeof(SourceDir),Inipath2);
OutputDebugString("* 2");
OutputDebugString(SourceDir);
FILE_NOTIFY_INFORMATION Buffer[1024];
DWORD BytesReturned;
CString m_dir("F:\\PRODUCT\\FILES");
HANDLE hDir = CreateFile( CString(SourceDir), // pointer to the file path
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS, //|FILE_FLAG_OVERLAPPED, // file attributes
NULL // file with attributes to copy
);
//endless loop
while (TRUE)
{
OutputDebugString("Watch Targeted Directory");
int ret = ReadDirectoryChangesW(hDir,&Buffer,sizeof(Buffer),TRUE,FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_LAST_WRITE,&dwBytes,NULL,NULL);
CString FileName = CString(Buffer[0].FileName);
CString AbsPathFileName = m_dir + "\\"+ CString(Buffer[0].FileName).Left(Buffer[0].FileNameLength / 2);
switch(Buffer[0].Action)
{
case FILE_ACTION_ADDED:
printf("%s\n+: %s\n","Triggered by add", AbsPathFileName);
OutputDebugString("A");
OutputDebugString(AbsPathFileName);
HChange.ProcessFile(AbsPathFileName,FileName);
break;
case FILE_ACTION_REMOVED:
printf("%s\nx: %s\n","Triggered by removed", AbsPathFileName);
OutputDebugString("B");
OutputDebugString(AbsPathFileName);
break;
case FILE_ACTION_MODIFIED:
printf("%s\nm: %s\n","Triggered by modified", AbsPathFileName);
OutputDebugString("C");
OutputDebugString(AbsPathFileName);
// ProcessFile(filename);
break;
case FILE_ACTION_RENAMED_OLD_NAME:
printf("%s\n%s -> %s\n","Triggered by rename", AbsPathFileName);
//filename = CString(Buffer[1].FileName).Left(Buffer[1].FileNameLength / 2));
OutputDebugString(AbsPathFileName);
break;
case FILE_ACTION_RENAMED_NEW_NAME:
printf("%s\n -> %s\n","Triggered by rename 2", AbsPathFileName);
OutputDebugString("E");
OutputDebugString(AbsPathFileName);
break;
}
}//while
CloseHandle( hDir );
return 0;
}
char HandleChange::ProcessFile(CString AbsPath,CString FileNm)
{
char TarDir[100];
char Inipath2[255];
CString CLcsDir = LcsDir;
strcpy(Inipath2, "f:\\tracsdata\\admin.ini");
GetPrivateProfileString("BETA","MAINDIR","f:\\product\\release\\",TarDir,sizeof(TarDir),Inipath2);
if(!strcmp(TarDir,"DEFAULT"))
{
LogFile("TarDir Not Found in INI File");
return 0;
}
if(CLcsDir.Find("\\\\0")<0)
CLcsDir += "\\";
LPCTSTR lpExistingFileName = AbsPath;
strcat (TarDir,FileNm);
LPCTSTR lpNewFileName = TarDir;
OutputDebugString("Process File");
OutputDebugString(lpExistingFileName);
OutputDebugString(lpNewFileName);
OutputDebugString(FileNm);
if(CopyFile(lpExistingFileName, lpNewFileName, false) == 0)
{
OutputDebugString("NOT OK");
ShowErrorMessageDebug( GetLastError() );
}
else
{
OutputDebugString("OK");
OutputDebugString("Copy Succeeded");
}
return 1;
}
void HandleChange::ShowErrorMessageDebug(DWORD err)
{
TCHAR errorMessage[256];
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
err,
NULL,
errorMessage,
256,
NULL);
OutputDebugString(errorMessage);
}
ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
ASKER
Actually I want to copy product1.txt to folder c:\product\beta.
thanks.