码迷,mamicode.com
首页 > 其他好文 > 详细

MFC: Create Directory

时间:2014-05-29 17:49:25      阅读:371      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

Original link: How to check if Directory already Exists in MFC(VC++)?

 

MSDN Links:

CreateDirectory function

GetFileAttributes function

GetLastError function

System Error Codes

 

Example:

VC++  MFC DLL project

bubuko.com,布布扣
#include "stdafx.h"
#include <windows.h>
#include <Shellapi.h>

    // To check if a file/folder exists:

    // Method 1: GetFileAttributes
    // Description: 
    // Retrieves file system attributes for a specified file or directory.
    // Return value:
    //   a) If the function succeeds, the return value contains the attributes of the specified file or directory. For a list of attribute values and their descriptions, see File Attribute Constants.
    //   b) If the function fails, the return value is INVALID_FILE_ATTRIBUTES. To get extended error information, call GetLastError.
    if (GetFileAttributes(szDirPath) == INVALID_FILE_ATTRIBUTES) {
        CreateDirectory(szDirPath,NULL);
    }

    // Method 2: CreateDirectory
    // Description:
    // Creates a new directory
    // Return value:
    //   a) If the function succeeds, the return value is nonzero.
    //   b) If the function fails, the return value is zero. To get extended error information, call GetLastError. 
    if(!CreateDirectory(szDirPath,NULL))
    { 
        if (GetLastError() == ERROR_ALREADY_EXISTS) {
            // directory already exists
        } else {
            // creation failed due to some other reasons
        }
    }
bubuko.com,布布扣

 

MFC: Create Directory,布布扣,bubuko.com

MFC: Create Directory

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/cindy-hu-23/p/3758415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!