【问题标题】:boost filesystem making long path under windows using \\?\使用 \\?\ 在 Windows 下提升文件系统制作长路径
【发布时间】:2020-02-20 14:25:08
【问题描述】:

它是如此简单,但我无法让它工作,我不知道为什么??
我只想用长路径创建目录。
我将\\\\?\\ 添加到E:\\... 以使其成为win api 所说的。
但徒劳无功.....只有错误。
我试过\\?\\?\ 没有成功。
这是代码:

// boost_create_directory.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <fstream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <ctime>
#include <iostream>
#include <map> //Needed to use the std::map class.
//#include "symbols_array2.h"
//#include "functions.h"
#include <boost/filesystem.hpp>
//#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>

////#include <filesystem>
////namespace fs = std::filesystem;
//#define DOWNLOAD_ALL true


int main()
{
using namespace std;
using namespace boost::filesystem;


//string localpath, binlocalfile, localfile;
string localpath = "\\\\?\\E:\\instruments\\symbol\\year\\month\\day\\";

//boost::filesystem::path abs_localpath;
////string localpath = "E:\\instruments\\symbol\\year\\month\\day\\";
boost::filesystem::path abs_localpath(localpath) ;


////string localpath = "\\\\?\\E:\\instruments\\symbol\\year\\month\\day\\";
////boost::filesystem::path abs_localpath("\\\\?\\E:\\instruments\\symbol\\year\\month\\day\\");
////string localpath = "E:/i/";

////boost::filesystem::path abs_localpath("\\?\E:\instruments\symbol\year\month\day\\");
////boost::filesystem::path path_argument(localpath);
////boost::filesystem::path path_native(path_argument.make_preferred());
////boost::filesystem::path abs_localpath(absolute(path_native));

//binlocalfile = localpath + "\\hourh_ticks.bin";
//localfile = localpath + "\\hourh_ticks.bi5";

//abs_localpath = boost::filesystem::absolute(localpath.c_str());
//abs_localpath = localpath;

//if (!boost::filesystem::exists(abs_localpath))
//{
    //boost::filesystem::path abs_localpath;
    //cout << current_path().string() << endl;
    //cout << abs_localpath << endl;
    //boost::filesystem::create_directory(abs_localpath);
for (int z = 0; z < 10; z++)
{

    if (boost::filesystem::create_directory(abs_localpath)) {
        std::cout << "Success making new directory" << "\n";
        //boost::filesystem::permissions(abs_localpath, perms_mask);
    }
    //localpath = localpath + "\\instruments\\symbol\\year\\month\\day";
    abs_localpath / "instruments\\symbol\\year\\month\\day\\";
    ////abs_localpath /= "\instruments\symbol\year\month\day\";

}
    //mkdir($localpath, 0777, true);
//}
boost::filesystem::path path("\\?\\E:\\MyStuff\\");

boost::filesystem::create_directory(path);
return 0;

}

我希望在这里找到答案。提前谢谢。

【问题讨论】:

    标签: boost boost-filesystem


    【解决方案1】:

    这是我的错。如果路径已经创建,create_directory 函数会创建单个目录,如果路径丢失则返回错误,所以我需要 create_directories 复数版本使路径的所有缺失元素,瞧。
    我希望他们将这些名称更改为 create_single_directory 或 create_target_directory 并将复数更改为 create_path_directories

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 2013-09-18
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 2014-07-20
      • 2020-11-05
      相关资源
      最近更新 更多