zoukankan      html  css  js  c++  java
  • C++ 文件系统操作 File System Operation

    Create Directory

    Using Windows api, include <windows.h>

        if (0 == ::CreateDirectoryA(_root.c_str(), nullptr))
        {
            DWORD errcode = ::GetLastError();
            if (errcode == ERROR_ALREADY_EXISTS)
            {
                return 0;
            }
            throw ISATGrabberException(CUtility::GetSysErrInfomation(errcode), errcode, __FILE__, __FUNCTION__, __LINE__);
        }

    Using C api in windows, include <direct.h>

        int ret = _mkdir(_root.c_str());
        if (ret != 0 && errno == ENOENT)
        {
            printf("%s, %d", strerror(errno), errno);
            return ret;
        }

    Check Direcotry exist

    Using Windows api

    Using C api in windows, include <sys/stat.h> and <sys/types.h>

            struct _stat buf;
            int ret = _stat(_root.c_str(), &buf); 
    
            CPPUNIT_ASSERT(0 == ret);
            CPPUNIT_ASSERT((buf.st_mode & _S_IFDIR) > 0);

    Using boost library

    ASSERT(boost::filesystem::status(_root).type() == boost::filesystem::directory_file);

    Remove Directory

    Using Windows API

    Using C api in windows, include <direct.h>

    _rmdir(dir.c_str());

    Using boost library

  • 相关阅读:
    IOS UIwebview 背景色调整
    文件的创建 判断是否存在文件 读取 写入
    IOS 关于ipad iphone5s崩溃 解决
    iOS tabbar 控制器基本使用
    iOS 关于流媒体 的初级认识与使用
    总结 IOS 7 内存管理
    iOS 应用首次开启 出现引导页面
    IOS UItableView 滚动到底 触发事件
    IOS 应用中从竖屏模式强制转换为横屏模式
    iOS 定位系统 知识
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/3088313.html
Copyright © 2011-2022 走看看