From: Walter Landry (wlandry_at_[hidden])
Date: 2003-08-14 05:03:52
I've started using boost::filesystem recently, and I'm mostly very
happy. One thing bothers me, though. Why does it implement any
restrictions, by default, on what kind of files it allows? From the
The following are not valid name char's: x01-x1F, <, >, :, ", /, \,
|, *, ?. Although these characters are supported by some operating
systems, they are disallowed by so many operating systems that they
are banned altogether.
I also noticed that you can't open a directory named "." or "..",
though I think "./" and "../" both work. Files starting or ending
with spaces also don't work.
I understand that I can (painfully) work around it by using a
different context, but I don't understand why boost::filesystem wants
to restrict me to a set of filenames that are portable. Isn't that a
bit too much handholding? I don't mind having an is_portable()
command or something similar, but it is incredibly annoying to have to
abide by someone else's filename restrictions.
I found a bug report at
and a discussion about this (though it focused more on "?" and "*") at
In particular, Beman Dawes said:
What is very explicitly not a supported use case is for providing
simply a new but still non-portable interface to non-portable
operating system API's. If that is the need, just call the
non-portable operating system API's directly.
If we were to take that to the extreme, then boost::filesystem should
only accept 8.3 filenames. What Beman seems to be missing is that he
has made an extremely nice interface to filesystems. It is much
simpler and easier to use within C++ than the non-portable API's. But
it is unneccesarily difficult to look at whatever files the user may
have created. This makes the library much less useful than it might
It is a trivial change to fix this (just take out the check), and I've
done this in my own copy. I'm attaching a patch with this email.
em/src/path_posix_windows.cpp 2003-07-18 13:22:15.000000000 -0400
2003-07-31 10:37:51.000000000 -0400
@@ -128,17 +128,6 @@
// error checking functions --------------------------------------------/
- bool generic_name( const std::string & name )
- return name.size() != 0
- && name.find_first_of( invalid_generic ) == std::string::npos
- && name != "."
- && name != ".."
- && *name.begin() != ' '
- && *(name.end()-1) != ' ';
bool posix_name( const std::string & name )
return name.find_first_not_of( valid_posix ) == std::string::npos
@@ -308,13 +297,6 @@
- if ( context == generic && !generic_name( name ) )
- boost::throw_exception( filesystem_error(
- "invalid name \"" + name + "\" in path: \"" + src + "\"" ) );
m_path += name;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk