CreateFile The CreateFile function creates or opens the following objects and returns a handle that can be used to access the object: Consoles Communications resources Directories (open only) Disk devices Files Mailslots Pipes HANDLE CreateFile( LPCTSTR lpFileName, // file name DWORD dwDesiredAccess, // access mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD DWORD dwCreationDisposition, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to template file );
{
CFileFind cfd; if(csDir.IsEmpty())
return false; csDir = csDir + "*";
if( cfd.FindFile(csDir) )
{
cfd.FindNextFile();
if(cfd.IsDirectory())
return true;
else
return false;
}
else
return false;
}
The CreateFile function creates or opens the following objects and returns a handle that can be used to access the object: Consoles
Communications resources
Directories (open only)
Disk devices
Files
Mailslots
Pipes
HANDLE CreateFile(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
);
SA.lpSecurityDescriptor = NULL;BOOL bRet = CreateDirectory((LPCTSTR)strYourPath, &SA);
DWORD dwError = GetLastError();
if (dwError == ERROR_ALREADY_EXISTS)//目录已经存在
...;
else
...;
ZeroMemory(&data, sizeof(WIN32_FIND_DATA));if (FindFirstFile(lpFileName, &data) ==INVALID_HANDLE_VALUE)
find ok;
else
{
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
find ok;
else
find fail;
}