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

#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
}
}

MFC: Create Directory的更多相关文章

  1. org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/hive/warehouse/page_view. Name node is in safe mode

    FAILED: Error in metadata: MetaException(message:Got exception: org.apache.hadoop.ipc.RemoteExceptio ...

  2. vsftp关于"550 create directory operation failed"问题解决

    前提: 昨天晚上配置好了vsftp, 但登陆后,除了浏览,什么也干不了.(如新建文件/文件夹, 删除文件, 重命名等都不可操作) 都是弹出 "550 create directory ope ...

  3. [hadoop]Cannot create directory /mdrill/tablelist/fact_seller_all_d. Name node is in safe mode.

    在执行mdrill创建表的时候报如下异常(蓝色部分为关键): [mdrill@hadoop1101 bin]$ ./bluewhale mdrill create ./create.sql higo ...

  4. Crontab could not create directory .ssh

    最近在利用 crontab 构建自动备份时,遇到了一个问题.我的脚本中包含了用于服务器用户切换使用的 ssh 命令.当我登录到服务器上时,脚本执行正常:当我没有登录到服务器上时,脚本执行失败,错误提示 ...

  5. 550 Create directory operation failed

    往Linux系统中上传文件时候,我们经常会使用FTP连接Linux,也经常会使用mkdir命令来创建目录.最近发现用mkdir创建目录时提示550 Create directory operation ...

  6. Linux虚拟主机通过FTP软件创建目录时提示550 Create Directory Operation Failed

    更新时间:2017-06-07 13:26:11   分享: 问题描述 通过FTP软件连接Linux虚拟主机,在尝试创建新目录时,服务器返回错误提示:550 Create Directory Oper ...

  7. 非root用户启动redis容器报错mkdir: cannot create directory '/bitnami/redis': Permission denied

    问题:使用docker启动容器时,报错如下 zh@debian:~/testPath$ docker-compose up redis Starting testpath_redis_1 ... do ...

  8. HTTP Status 500 - Unable to create directory

    分析原因: 例如:java web项目 上传图片创建文件夹cd /data/apps/static-web/sjk/driver/attachment/编号/文件名称.jpg 在创建文件目录 /dat ...

  9. Hadoop "Cannot create directory .Name node is in safe mode."解决方案

    转载自:http://www.waitig.com/hadoop-name-node-is-in-safe-mode.html 在使用Hadoop建立文件的时候,出现“Cannot create di ...

随机推荐

  1. 关于 javascript:void(0) 的使用

    在 Wep App 中,我们经常需要在 JavaScript 中处理链接的点击.因此,我们希望用户点击 <a> 元素时阻止它的默认行为.此时我们可以用很多不同的方法来处理.例如: < ...

  2. ECSHOP在线手册布局参考图--通用活动页 group_list.dwt等

        A.购物车 1,设置方法 程序自动读取购物车的商品数量 2,代码相关 cart.lbi 中 {insert_scripts files='transport.js'} <div clas ...

  3. CentOS 6.5 下载地址

    CentOS 6.5 主要改动 Precision Time Protocol(精确时间协议)—— 原先是项技术预览 —— 现在已获全面支持.以下驱动程序支持网络时间戳印:bnx2x.tg3.e100 ...

  4. paip.mysql备份慢的解决

    paip.mysql备份慢的解决.txt 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/att ...

  5. 访谈将源代码的函数 strcpy/memcpy/atoi/kmp/quicksort

    一.社论 继上一次发表了一片关于參加秋招的学弟学妹们怎样准备找工作的博客之后,反响非常大.顾在此整理一下,以便大家复习.好多源自july的这篇博客,也有非常多是我自己整理的.希望大家可以一遍一遍的写. ...

  6. linux内核系统调用和标准C库函数的关系分析

    http://blog.csdn.net/skyflying2012/article/details/10044343

  7. 浅谈ASP脚本的解释

    10多年前,ASP的出现使全世界的WEB设计者摆脱了C/C++的繁杂,大幅提升了页面的开发效率 然而一直到数年之后,asp的解释一直握在微软手里,后来阿帕奇也支持asp了,虽然没有IIS那么强大,但是 ...

  8. java code to byte code--partone--reference

    Understanding how Java code is compiled into byte code and executed on a Java Virtual Machine (JVM) ...

  9. WebAPI返回JSON的正确格式

    最近打算用WebAPI做服务端接口,返回JSON供ANDROID程序调用,结果试了好几次JSONObject都无法解析返回的JSON字符串.看了一下服务端代码: public string Get() ...

  10. logstash-input-file 参数说明

    参数 close_older close_older: # This has different implications depending on if a file is being tailed ...