Search code examples
boostboost-filesystem

boost filesystem making long path under windows using \\?\


it is so simple but i can not make it work and i do not know why??
i just want to make directory with long path.
i add \\\\?\\ to E:\\... to make it as win api says .
but in vain.....nothing but error.
i tried \\?\ and \?\ with no success.
this is the code :

// 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;

}

i hope to find answer here.thanks in advance.


Solution

  • it was my fault .the create_directory function make single directory if path is already created and return with error if path is missing,So i needed create_directories the plural version make all missing elements of path and voila.
    i wish they change these names to create_single_directory or create_target_directory and change the plural to create_path_directories