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

  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <Shellapi.h>
  4.  
  5. // To check if a file/folder exists:
  6.  
  7. // Method 1: GetFileAttributes
  8. // Description:
  9. // Retrieves file system attributes for a specified file or directory.
  10. // Return value:
  11. // 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.
  12. // b) If the function fails, the return value is INVALID_FILE_ATTRIBUTES. To get extended error information, call GetLastError.
  13. if (GetFileAttributes(szDirPath) == INVALID_FILE_ATTRIBUTES) {
  14. CreateDirectory(szDirPath,NULL);
  15. }
  16.  
  17. // Method 2: CreateDirectory
  18. // Description:
  19. // Creates a new directory
  20. // Return value:
  21. // a) If the function succeeds, the return value is nonzero.
  22. // b) If the function fails, the return value is zero. To get extended error information, call GetLastError.
  23. if(!CreateDirectory(szDirPath,NULL))
  24. {
  25. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  26. // directory already exists
  27. } else {
  28. // creation failed due to some other reasons
  29. }
  30. }

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. Struts的类型转换

    struts中jsp提交的数据,struts会自动转换为action中的属性类型: 对于基本的数据类型以及日期类型会自动转换: 就像前面那一篇博客的代码封装一样,会把字符串类型传过来的数据转化为相应的 ...

  2. 9 个让 JavaScript 调试更简单的 Console 命令

    一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...

  3. linq to sql 扩展方法

    老赵的博客:http://blog.zhaojie.me/2008/02/using-translate-method-and-modify-command-text-before-query-in- ...

  4. Win8.1激活

    激活查询:在桌面状态下输入“Win+R”,进入运行栏目,输入slmgr.vbs -dlv 显示:最为详尽的激活信息,包括:激活ID.安装ID.激活截止日期 http://www.nruan.com/w ...

  5. TableControl大小变化

    TableControl跟随Form大小变化: 选中TableControl,而不是TablePage,右侧Layout: 可以对其设置居上.居下等位置

  6. C++Vector使用方法

    C++内置的数组支持容器的机制,可是它不支持容器抽象的语义.要解决此问题我们自己实现这种类.在标准C++中,用容器向量(vector)实现.容器向量也是一个类模板.标准库vector类型使用须要的头文 ...

  7. web工作方式,浏览网页,打开浏览器,输入网址按下回车键,然后会显示出内容,这个过程是怎样的呢?

    以下内容摘自<Go Web编程>,介绍的通俗易懂. 我们平时浏览网页的时候,会打开浏览器,输入网址后按下回车键,然后就会显示出你想要浏览的内容.在这个看似简单的用户行为背后,到底隐藏了些什 ...

  8. [VirtualBox] Install Ubuntu 14.10 error 5 Input/output error

    After you download the VirtualBox install package and install it (just defualt setting). Then you sh ...

  9. mysqldump原理4

    http://blog.csdn.net/dba_waterbin/article/details/23611601?utm_source=tuicool&utm_medium=referra ...

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

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