首页 > 其他 > 详细

MFC: Create Directory

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!