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

  • 相关阅读:
    JSON学习笔记-5
    JSON学习笔记-4
    JSON学习笔记-3
    JSON学习笔记-2
    JSON学习笔记-1
    stm32f103各个型号芯片之间程序移植(stm32的兼容问题)
    如何找回微信小程序源码?2020年微信小程序反编译最新教程 小宇子李
    git常用命令
    304 怎么办 怎么解决 缓存解决
    微信小程序 CSS border-radius元素 overflow:hidden失效问题 iPhone ios 苹果兼容问题 伪类元素
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/3088313.html
Copyright © 2011-2022 走看看