Discussion:
boost::filesystem path problem under WINDOWS
avanindra singh
2010-12-13 08:09:32 UTC
Permalink
Hi,
 
Here is the code snippet I am using under windows in VS2008.
 
#define BOOST_WINDOWS_PATH
#define BOOST_WINDOWS_API
#include "stdafx.h"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
#include "string"
#include "conio.h"
#include "vector"
 
using namespace std;
using namespace boost::filesystem;
 
 
 
int _tmain(int argc, _TCHAR* argv[])
{
string _path = "E:\\doggy";
path dir_path(_path.c_str());

vector< pair<string,bool> > _file_jpeg_pair;


string full_list_path = _path+"\\" + "list.txt";

string bundle_path_str = _path+"\\" + "bundle";

path bundle_path(_path.c_str());


//creating bundle directory
cout<<bundle_path<<endl;
//if( !exists( bundle_path ) )
create_directory(bundle_path);
cout<<"directory created "<<endl;
getch();
return 0;
}
 
 
This code is giving run time unhandled exception, so for that matter any other call of boost filesystem.
 
Strange thing is the Windows path E:\doggy is being printed as E:/doggy, seems like the path is getting converted to POSIX format.
 
Can anyone please help me here?...
 
Thanks
Avanindra
Jeff Flinn
2010-12-13 15:03:12 UTC
Permalink
Post by avanindra singh
Hi,
Here is the code snippet I am using under windows in VS2008.
#define BOOST_WINDOWS_PATH
#define BOOST_WINDOWS_API
You shouldn't be manually defining these, and would normally get a
compile error...
Post by avanindra singh
#include "stdafx.h"
but you probably are configure to use precompiled headers, so anything
before stdafx.h is ignored.
Post by avanindra singh
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
#include "string"
#include "conio.h"
#include "vector"
using namespace std;
using namespace boost::filesystem;
int _tmain(int argc, _TCHAR* argv[])
{
string _path = "E:\\doggy";
path dir_path(_path.c_str());
vector< pair<string,bool> > _file_jpeg_pair;
string full_list_path = _path+"\\" + "list.txt";
string bundle_path_str = _path+"\\" + "bundle";
path bundle_path(_path.c_str());
//creating bundle directory
cout<<bundle_path<<endl;
//if( !exists( bundle_path ) )
create_directory(bundle_path);
cout<<"directory created "<<endl;
getch();
return 0;
}
This code is giving run time unhandled exception, so for that matter any
other call of boost filesystem.
Catch the unhandled exception and see what the problem is. Filesystem
throws boost::system::system_error exceptions.
Post by avanindra singh
Strange thing is the Windows path E:\doggy is being printed as E:/doggy,
seems like the path is getting converted to POSIX format.
Depending on the boost filesystem version you can ask for native
formatted strings.

Jeff
avanindra singh
2010-12-13 17:53:49 UTC
Permalink
Hi Jeff,
Thanks for the reply.

I caught the exception using this code:
  try{   create_directory(bundle_path);  }  catch(boost::system::system_error const &e)  {   cerr<<diagnostic_information(e)<<endl;  }

The printed output was
Throw in function (unknown)Dynamic exception type: class boost::exception_detail::clone_impl<struct boost::exception_detail::error_info_injector<class boost::filesystem::basic_filesystem_error<class boost::filesystem::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem::path_traits> > > >std::exception::what: boost::filesystem::create_directory: The filename, directory name, or volume label syntax is incorrect: "E:\doggy"

Can you point me what mistake I am doing here?..I believe the syntax of path is correct.
ThanksAvanindra
--- On Mon, 13/12/10, Jeff Flinn <***@hotmail.com> wrote:

From: Jeff Flinn <***@hotmail.com>
Subject: Re: [Boost-users] boost::filesystem path problem under WINDOWS
To: boost-***@lists.boost.org
Date: Monday, 13 December, 2010, 8:33 PM
Hi,
  Here is the code snippet I am using under windows in VS2008.
  #define BOOST_WINDOWS_PATH
#define BOOST_WINDOWS_API
You shouldn't be manually defining these, and would normally get a compile error...
#include "stdafx.h"
but you probably are configure to use precompiled headers, so anything before stdafx.h is ignored.
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
#include "string"
#include "conio.h"
#include "vector"
  using namespace std;
using namespace boost::filesystem;
    int _tmain(int argc, _TCHAR* argv[])
{
string _path = "E:\\doggy";
path dir_path(_path.c_str());
vector< pair<string,bool> > _file_jpeg_pair;
string full_list_path = _path+"\\" + "list.txt";
string bundle_path_str = _path+"\\" + "bundle";
path bundle_path(_path.c_str());
//creating bundle directory
cout<<bundle_path<<endl;
//if( !exists( bundle_path ) )
create_directory(bundle_path);
cout<<"directory created "<<endl;
getch();
return 0;
}
   This code is giving run time unhandled exception, so for that matter any other call of boost filesystem.
Catch the unhandled exception and see what the problem is. Filesystem throws boost::system::system_error exceptions.
Strange thing is the Windows path E:\doggy is being printed as E:/doggy, seems like the path is getting converted to POSIX format.
Depending on the boost filesystem version you can ask for native formatted strings.

Jeff
Ian Bruntlett
2010-12-13 18:03:18 UTC
Permalink
Hi avanindra,

std::exception::what: boost::filesystem::create_directory: The filename,
directo
ry name, or volume label syntax is incorrect: "E:\doggy"

OK, I don't have the full story here. Is the directory name being specified
in the C++ source code? If so then remember that "\" is used for character
escape sequences. If you are specifying the name in the source code, you may
need to type "E:\\doggy". The double "\" will resolve to a single "\" in the
executable.

HTH,



Ian
--
-- ACCU - Professionalism in programming - http://www.accu.org/
avanindra singh
2010-12-13 19:01:14 UTC
Permalink
Hi Ian,
escape character is not the problem. I would put my code here:
#include "stdafx.h"#include "Windows.h"#include <boost/filesystem/operations.hpp>#include <boost/filesystem/fstream.hpp>#include <iostream>#include "string"#include "conio.h"#include "vector"#include <boost/exception/diagnostic_information.hpp>
#define BOOST_WINDOWS_PATH #define BOOST_WINDOWS_APIusing namespace std;using namespace boost::filesystem; 

extern "C" void straight_to_debugger(unsigned int, EXCEPTION_POINTERS*){    throw;}extern "C" void (*old_translator)(unsigned, EXCEPTION_POINTERS*)         = _set_se_translator(straight_to_debugger);


int _tmain(int argc, _TCHAR* argv[]){ string _path = "E:\\doggy";
path dir_path(_path.c_str());    vector< pair<string,bool> > _file_jpeg_pair;      string full_list_path = _path+"\\" + "list.txt";    string bundle_path_str = _path+"\\" + "bundle";    path bundle_path(_path.c_str());    //creating bundle directory  cout<<bundle_path<<endl;
  //boost::system::system_error exceptions;  //if( !exists( bundle_path ) )  try{   create_directory(bundle_path);  }  catch(boost::system::system_error const &e)  {   cerr<<diagnostic_information(e)<<endl;  }  cout<<"directory created "<<endl;
  getch();
return 0;}
You can see that, I have used proper path. The problem is the Windows style path is getting converted somehow in POSIX format. As I printed the path and it came out to be
E:/doggy
Can you point me what mistake I am doing here.
ThanksAvanindra
--- On Mon, 13/12/10, Ian Bruntlett <***@gmail.com> wrote:

From: Ian Bruntlett <***@gmail.com>
Subject: Re: [Boost-users] boost::filesystem path problem under WINDOWS
To: boost-***@lists.boost.org
Date: Monday, 13 December, 2010, 11:33 PM

Hi avanindra,

std::exception::what: boost::filesystem::create_directory: The filename, directory name, or volume label syntax is incorrect: "E:\doggy"
OK, I don't have the full story here. Is the directory name being specified in the C++ source code? If so then remember that "\" is used for character escape sequences. If you are specifying the name in the source code, you may need to type "E:\\doggy". The double "\" will resolve to a single "\" in the executable.


HTH,



Ian
--
-- ACCU - Professionalism in programming - http://www.accu.org/


-----Inline Attachment Follows-----
Ian Bruntlett
2010-12-13 19:17:39 UTC
Permalink
Hi avanindra,
Post by avanindra singh
You can see that, I have used proper path. The problem is the Windows style
path is getting converted somehow in POSIX format. As I printed the path and
it came out to be
E:/doggy
Can you point me what mistake I am doing here.
Well... all I can suggest is to use the debugger to trace into the functions
that modify your variables. That's the bad news. The good news is that you
have the source code in question so it should be a no-brainer for you:)

HTH,


Ian
--
-- ACCU - Professionalism in programming - http://www.accu.org/
Jeff Flinn
2010-12-13 20:23:06 UTC
Permalink
Post by avanindra singh
Hi Jeff,
Thanks for the reply.
try{
create_directory(bundle_path);
}
catch(boost::system::system_error const &e)
{
cerr<<diagnostic_information(e)<<endl;
}
The printed output was
Throw in function (unknown)
Dynamic exception type: class boost::exception_detail::clone_impl<struct
exception_detail::error_info_injector<class
boost::filesystem::basic_filesystem_
error<class boost::filesystem::basic_path<class
std::basic_string<char,struct st
d::char_traits<char>,class std::allocator<char> >,struct
boost::filesystem::path
_traits> > > >
std::exception::what: boost::filesystem::create_directory: The filename,
directo
ry name, or volume label syntax is incorrect: "E:\doggy"
Can you point me what mistake I am doing here?..I believe the syntax of path is correct.
Please don't top post.

Lookup the documentation on create_directory versus create_directories.
Simplify your test case to just what's needed for creating your directories.

Jeff

Loading...