[filesystem] basic_path question

Hi, I create the following object: boost::filesystem::path mypath( "SomeFolder/OnWindows/SubFolder" ); In Microsoft Windows, the standard slash direction is "\", so when I run the above in the debugger, I notice m_path is still using forward slashes ("/"). I would have expected the slashes to be normalized. Am I misunderstanding something? How can I construct a path object like above and have it normalize the slashes? Thanks.

Hi Robert, I have used Boost paths on Windows like this: namespace bf = boost::filesystem; bf::path temp("C:\\Windows\\System32\\", bf::native); Adding the "native" parameter tells the path object it is parsing a Windows path (if compiling on Windows). To my knowledge, the path object will always store paths in its own internal format, which uses front slashes as directory separators. More info on this is in the boost::filesystem documentation. The basic_path::file_string() method returns the path in the operating system native format, if I'm not mistaken. Regards, Markus. Robert Dailey wrote:
Hi,
I create the following object:
boost::filesystem::path mypath( "SomeFolder/OnWindows/SubFolder" );
In Microsoft Windows, the standard slash direction is "\", so when I run the above in the debugger, I notice m_path is still using forward slashes ("/"). I would have expected the slashes to be normalized. Am I misunderstanding something? How can I construct a path object like above and have it normalize the slashes? Thanks. ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I've read the documentation a little closer at this page:
http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/index.htm#tutorial
I find that it will store paths as forward slashes, and only when you call
basic_path::file_string() will it convert to the platform format. However at
this time I cannot figure out if file_string() is returning a std::string
by-reference or by-value (Still looking through the source for answers to
this).
On Thu, Apr 24, 2008 at 2:49 PM, Markus Svilans
Hi Robert,
I have used Boost paths on Windows like this:
namespace bf = boost::filesystem; bf::path temp("C:\\Windows\\System32\\", bf::native);
Adding the "native" parameter tells the path object it is parsing a Windows path (if compiling on Windows).
To my knowledge, the path object will always store paths in its own internal format, which uses front slashes as directory separators. More info on this is in the boost::filesystem documentation.
The basic_path::file_string() method returns the path in the operating system native format, if I'm not mistaken.
Regards, Markus.
Robert Dailey wrote:
Hi,
I create the following object:
boost::filesystem::path mypath( "SomeFolder/OnWindows/SubFolder" );
In Microsoft Windows, the standard slash direction is "\", so when I run the above in the debugger, I notice m_path is still using forward slashes ("/"). I would have expected the slashes to be normalized. Am I misunderstanding something? How can I construct a path object like above and have it normalize the slashes? Thanks. ------------------------------------------------------------------------
_______________________________________________ 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

I have another question.
Suppose I have the following:
boost::filesystem::path myPath( "C:/somefolder/somefile" );
myPath += ".txt";
Notice the 2nd line of code. This isn't legal. What is the cleanest way to
append an extension to a file path? I don't think /= will work; if I
remember correctly it will add "/.txt".
On Thu, Apr 24, 2008 at 3:00 PM, Robert Dailey
I've read the documentation a little closer at this page: http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/index.htm#tutorial
I find that it will store paths as forward slashes, and only when you call basic_path::file_string() will it convert to the platform format. However at this time I cannot figure out if file_string() is returning a std::string by-reference or by-value (Still looking through the source for answers to this).
On Thu, Apr 24, 2008 at 2:49 PM, Markus Svilans
wrote: Hi Robert,
I have used Boost paths on Windows like this:
namespace bf = boost::filesystem; bf::path temp("C:\\Windows\\System32\\", bf::native);
Adding the "native" parameter tells the path object it is parsing a Windows path (if compiling on Windows).
To my knowledge, the path object will always store paths in its own internal format, which uses front slashes as directory separators. More info on this is in the boost::filesystem documentation.
The basic_path::file_string() method returns the path in the operating system native format, if I'm not mistaken.
Regards, Markus.
Robert Dailey wrote:
Hi,
I create the following object:
boost::filesystem::path mypath( "SomeFolder/OnWindows/SubFolder" );
In Microsoft Windows, the standard slash direction is "\", so when I run the above in the debugger, I notice m_path is still using forward slashes ("/"). I would have expected the slashes to be normalized. Am I misunderstanding something? How can I construct a path object like above and have it normalize the slashes? Thanks. ------------------------------------------------------------------------
_______________________________________________ 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

Robert Dailey schrieb:
boost::filesystem::path myPath( "C:/somefolder/somefile" ); myPath += ".txt";
Notice the 2nd line of code. This isn't legal. What is the cleanest way to append an extension to a file path? I don't think /= will work; if I remember correctly it will add "/.txt".
I think you basically have the option of doing: 1) myPath = myPath.branch_path() / (myPath.leaf() + ".txt"); 2) string tmp = p.leaf(); p.remove_leaf(); p /= tmp + ".txt"; Both are not really pretty... Regards, Mika

On Thu, Apr 24, 2008 at 5:01 PM, Mika Fischer
Robert Dailey schrieb:
boost::filesystem::path myPath( "C:/somefolder/somefile" ); myPath += ".txt";
Notice the 2nd line of code. This isn't legal. What is the cleanest way to append an extension to a file path? I don't think /= will work; if I remember correctly it will add "/.txt".
I think you basically have the option of doing:
1) myPath = myPath.branch_path() / (myPath.leaf() + ".txt");
2) string tmp = p.leaf(); p.remove_leaf(); p /= tmp + ".txt";
Both are not really pretty...
Regards, Mika
I figured that would be the approach I would have to take. I'm making best efforts to only append a filename when the extension is present, since as far as I can tell being preemptive like that is the cleanest solution.

Robert Dailey wrote:
Robert Dailey schrieb:
> boost::filesystem::path myPath(
"C:/somefolder/somefile" );
> myPath += ".txt"; > > Notice the 2nd line of code. This isn't legal. What is
the cleanest way
> to append an extension to a file path? I don't think
/= will work; if I
> remember correctly it will add "/.txt".
I think you basically have the option of doing:
1) myPath = myPath.branch_path() / (myPath.leaf() +
".txt");
2) string tmp = p.leaf(); p.remove_leaf(); p /= tmp + ".txt";
Both are not really pretty...
Regards, Mika
I figured that would be the approach I would have to take. I'm
making best efforts
to only append a filename when the extension is present, since as far as I can tell being preemptive like that is the cleanest solution.
Have you looked at ::boost::filesystem::change_extension??? Somehow it is referred to as replace_extension in the docs, but this function will do what you are discussing I think. -- John Femiani

On Thu, Apr 24, 2008 at 6:29 PM, John Femiani
Robert Dailey wrote:
Robert Dailey schrieb:
> boost::filesystem::path myPath(
"C:/somefolder/somefile" );
> myPath += ".txt"; > > Notice the 2nd line of code. This isn't legal. What is
the cleanest way
> to append an extension to a file path? I don't think
/= will work; if I
> remember correctly it will add "/.txt".
I think you basically have the option of doing:
1) myPath = myPath.branch_path() / (myPath.leaf() +
".txt");
2) string tmp = p.leaf(); p.remove_leaf(); p /= tmp + ".txt";
Both are not really pretty...
Regards, Mika
I figured that would be the approach I would have to take. I'm
making best efforts
to only append a filename when the extension is present, since as far as I can tell being preemptive like that is the cleanest solution.
Have you looked at ::boost::filesystem::change_extension??? Somehow it is referred to as replace_extension in the docs, but this function will do what you are discussing I think.
-- John Femiani
I did not see that in the boost.filesystem.basic_path reference documentation.

Robert Dailey wrote:
Have you looked at
::boost::filesystem::change_extension???
Somehow it is referred to as replace_extension in the
docs, but this
function will do what you are discussing I think.
-- John Femiani
I did not see that in the boost.filesystem.basic_path reference
documentation. replace_extension is documented here: http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/refer ence.html#Convenience-functions but in the actual library it is named 'change_extension' (I dont know why) Personally I find the documentation for filesystem pretty hard to navigate. I recommend using doxygen to navigate the source, since that gives a fairly complete reference. I use a PC so I can generate a chm file with a searchable index and everything. (I tried to attach the docs but the message got to big for the mailing list) -- John Femiani

On Thu, Apr 24, 2008 at 11:32 PM, John Femiani
Robert Dailey wrote:
Have you looked at
::boost::filesystem::change_extension???
Somehow it is referred to as replace_extension in the
docs, but this
function will do what you are discussing I think.
-- John Femiani
I did not see that in the boost.filesystem.basic_path reference
documentation.
replace_extension is documented here:
http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/refer ence.html#Convenience-functions
but in the actual library it is named 'change_extension' (I dont know why)
Personally I find the documentation for filesystem pretty hard to navigate. I recommend using doxygen to navigate the source, since that gives a fairly complete reference. I use a PC so I can generate a chm file with a searchable index and everything.
(I tried to attach the docs but the message got to big for the mailing list)
-- John Femiani
That's the thing, I love Boost but I really cannot stand the documentation (In fact I don't know anyone that actually likes it). You guys should desperately consider using Doxygen (As stated by John). Pause updating boost implementation for a few days and start working on documentation!
participants (4)
-
John Femiani
-
Markus Svilans
-
Mika Fischer
-
Robert Dailey