文档介绍:踏雪无痕
VC判断目录是否存在
分类: C++ 2011-08-19 13:33 256人阅读评论(0) 收藏举报
 
VC判断目录是否存在,如果不存在则创建新目录:
// Test Whether the dir exist
CString m_dir;
if ((1) == “\\”)
    m_dir = (()-1);
if (GetFileAttributes(m_dir) == FILE_ATTRIBUTE_DIRECTORY)
    return TURE;
else
    CreateAllDirectory(m_dir); 
// Function CreateAllDirectory
// recursive function
void CreateAllDirectory(CString Dir)
{
if ((1) == “\\”)
    Dir = (()-1);
if (GetFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
    return;
else if (GetFileAttributes(Dir) != -1)
{
if (DeleteFile(Dir))                              // delete the file with the same name
if (CreateDirectory(Dir, NULL))
    return;
MessageBox(_T(“Can not create directory for captured pictures”), NULL, MB_OK