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

  • 相关阅读:
    Python标准模块--logging
    Spark中决策树源码分析
    常见的相似或相异程度计算方法
    mpi4py实践
    集成学习
    决策树
    git使用
    Ubuntu 14.04 64bit 安装tensorflow(GPU版本)
    KNN算法
    一致性哈希算法原理及其在分布式系统中的应用
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/3088313.html
Copyright © 2011-2022 走看看