Tuesday, July 14, 2009

MFC - Wait until a file or path does or not not exist

useful code to wait till a file path does or not exists




BOOL FileExist( LPTSTR pszFilePath )
{
BOOL bRetVal;

if( _taccess( pszFilePath , 0 ) == 0 )
{
bRetVal = TRUE;
}
else
{
bRetVal = FALSE;
}

return bRetVal;
}



BOOL WaitForFileNotExist( LPTSTR pszPath , DWORD dwTimeout )
{
int nCount = dwTimeout/100;
int nCounter = 0;

if( nCount < 1 )
{
// timeout must be more or equal to 1 !!
return FALSE;
}

// only exit the loop when the file is present or timeout occurs
while( !FileExist(pszPath) && nCounter < nCount )
{
Sleep(100);
nCounter++;
}

if( nCounter >= nCount )
{
return FALSE;
}

return TRUE;
}

BOOL WaitForFileExist( LPTSTR pszPath , DWORD dwTimeout )
{
int nCount = dwTimeout/100;
int nCounter = 0;

if( nCount < 1 )
{
// timeout must be more or equal to 1 !!
return FALSE;
}

// only exit the loop when the file is present or timeout occurs
while( !FileExist(pszPath) && nCounter < nCount )
{
::Sleep(100);
nCounter++;
}

if( nCounter >= nCount )
{
return FALSE;
}

return TRUE;
}

0 תגובות:

Post a Comment

 
Home | About | Link | Link
Simple Proff Blogger Template Created By Herro | Inspiring By Busy Bee Woo Themes