Problem with fs::path initialization in windows
Hello, I have a little problem with initialization of boost filesystem path. I'm working on Cygwin in Windows XP. The fs::initial_path() and fs::current_path() both work ok and show something like: C:\cygwin\boost But when I try to use a path of my own, say: fs::path full_path( "C:\\cygwin\\boost" ); I get thrown with an exception. Same deal with the rest of the combinations I can think of: C:/cygwin/boost c:/cygwin/boost. c/cygwin and /cygwin don't throw but the paths are not found. So how do initialize the fs::path with a Windows type of directory path? Timo
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Timo Sent: Monday, March 12, 2007 6:41 AM To: boost-users@lists.boost.org Subject: [Boost-users] Problem with fs::path initialization in windows I have a little problem with initialization of boost filesystem path. I'm working on Cygwin in Windows XP. But when I try to use a path of my own, say: fs::path full_path( "C:\\cygwin\\boost" ); I get thrown with an exception. Same deal with the rest of the combinations I can think of: C:/cygwin/boost c:/cygwin/boost. c/cygwin and /cygwin don't throw but the paths are not found. So how do initialize the fs::path with a Windows type of directory path? [Nat] Have you tried something like: fs::path full_path("some string", fs::no_check); ? I've found that the best policy with boost::filesystem is to explicitly disable its name check on every instantiation. In fact I've introduced a local subclass with a constructor accepting a path string; the constructor simply passes the string to the base-class constructor along with boost::filesystem::no_check.
"Nat Goodspeed"
[Nat] Have you tried something like: fs::path full_path("some string", fs::no_check); ? This worked like a charm. So for example: fs::path my_path("C:\\cygwin", fs::no_check); works just as it is supposed to.
I managed to circumvent the problem with a bubblegum solution, but yours is more usable. My solution was to go back to the root(C:) with /../-steps and head back up from there. For example: fs::path my_path("./../../../some_dir/some_subdir/"); Thanks Nat!
Hi, try this fs::path full_path( "C:\\cygwin\\boost", fs::native ); Nat Goodspeed schrieb:
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Timo Sent: Monday, March 12, 2007 6:41 AM To: boost-users@lists.boost.org Subject: [Boost-users] Problem with fs::path initialization in windows
I have a little problem with initialization of boost filesystem path. I'm working on Cygwin in Windows XP.
But when I try to use a path of my own, say: c I get thrown with an exception. Same deal with the rest of the combinations I can think of: C:/cygwin/boost c:/cygwin/boost. c/cygwin and /cygwin don't throw but the paths are not found.
So how do initialize the fs::path with a Windows type of directory path?
[Nat] Have you tried something like: fs::path full_path("some string", fs::no_check); ? I've found that the best policy with boost::filesystem is to explicitly disable its name check on every instantiation. In fact I've introduced a local subclass with a constructor accepting a path string; the constructor simply passes the string to the base-class constructor along with boost::filesystem::no_check. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
fs::native throws an exception. But fs::no_check works. Just wondering if
this is a "feature" that the boost developers are aware of.
Timo
"Heiko Fechner"
Hi,
try this fs::path full_path( "C:\\cygwin\\boost", fs::native );
Nat Goodspeed schrieb:
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Timo Sent: Monday, March 12, 2007 6:41 AM To: boost-users@lists.boost.org Subject: [Boost-users] Problem with fs::path initialization in windows
I have a little problem with initialization of boost filesystem path. I'm working on Cygwin in Windows XP.
But when I try to use a path of my own, say: c I get thrown with an exception. Same deal with the rest of the combinations I can think of: C:/cygwin/boost c:/cygwin/boost. c/cygwin and /cygwin don't throw but the paths are not found.
So how do initialize the fs::path with a Windows type of directory path?
[Nat] Have you tried something like: fs::path full_path("some string", fs::no_check); ? I've found that the best policy with boost::filesystem is to explicitly disable its name check on every instantiation. In fact I've introduced a local subclass with a constructor accepting a path string; the constructor simply passes the string to the base-class constructor along with boost::filesystem::no_check. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--------------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Timo
fs::native throws an exception. But fs::no_check works. Just wondering if this is a "feature" that the boost developers are aware of.
Timo
It's not an issue with boost::filesystem so much as a design choice made by the cygwin boost package maintainer. The package is compiled with BOOST_POSIX defined, telling the library to expect POSIX paths. See http://boost.org/libs/filesystem/doc/index.htm#Cgywin [sic]. The reason it still works after you pass fs::no_check is that the cygwin emulation layer can correctly interpret both kinds of paths, even though boost::filesystem isn't aware of that fact. If you are compiling programs in cygwin, you should expect to use POSIX paths anyway, otherwise you could just compile in MinGW instead. So instead of c:\whatever, use /cygdrive/c/whatever. Or instead of c:\cygwin\whatever, just /whatever. -Lewis
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Heiko Fechner Sent: Monday, March 12, 2007 10:13 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Problem with fs::path initialization in windows try this fs::path full_path( "C:\\cygwin\\boost", fs::native ); [Nat] Forgive me for being cynical, but this is what the various constructs look like to me. fs::path full_path(my_path_string); // Always crash, no matter how I try to express my path. fs::path full_path(my_path_string, fs::no_check); // Correctly expresses my desire: never throw when constructing this object. fs::path full_path(my_path_string, fs::native); // Only crash when a customer is running the program.
participants (4)
-
Heiko Fechner
-
Lewis Hyatt
-
Nat Goodspeed
-
Timo