-
UNC problem
Why does this code not work on an UNC directory?. I have a similar FileExist function that works with the same FindFirstFile API call.
Code:
BOOL WINAPI vbDirExist(LPCTSTR lpszDirName)
/*
Last modified: 19/6/2001.
Check if a directory exist.
Returns true if the directory exist, otherwise false.
To get extended error information, call GetLastError.
TODO: Doesn't work on network
Parameters ************************************************************
lpszDirName: Full directory name
***********************************************************************
*/
{
char szBuffer[MAX_PATH];
WIN32_FIND_DATA tWFD;
HANDLE hFile = 0;
DWORD dwError = 0;
int len = 0;
// Copy filename to buffer & remove trailing slash
memset(szBuffer, NULL, MAX_PATH);
lstrcpy( (LPTSTR)szBuffer, lpszDirName);
len = lstrlen( (LPTSTR)szBuffer);
if (szBuffer[len - 1] == '\\')
szBuffer[len - 1] = '\0';
hFile = FindFirstFile((LPTSTR)szBuffer, &tWFD);
//if a valid file handle was returned, and the
//directory attribute is set the folder exists
if (hFile != INVALID_HANDLE_VALUE)
{
FindClose(hFile);
return ((tWFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
}
else {
dwError = GetLastError();
if (dwError == ERROR_FILE_NOT_FOUND)
// Clear error
SetLastError(ERROR_SUCCESS);
return FALSE;
}
}