Using filenames starting with a dot
Hi everyone! I wanted to create a hidden files (for configuration etc) by starting the filename with a dot on a Linux system. The following line aborts the program when filename is a std::string starting with a dot:
boost::filesystem::path filename_complete = basepath / filename;
Are there any tricks for that? Thanks! Uli
My observation regarding this issue is as follows: boost::filesystem is about portability. Or more to the point: about portable paths. So it will check wether your path is portable to ALL systems it knows. As that includes systems which use the period as directory delimiter it is not a portable path component. Here's a look at the documentation: "portable_name = windows_name(name) && portable_posix_name(name), and first character not period or hyphen." As portable_name is the default name_check function this will throw an exception. Define native_check or posix_check to make it POSIX only and thus allow the period at the beginning. eg: boost::filesystem::path filename_complete(basepath, nativ_check); path /= filename; Regards, Hagen.
Uli Türk wrote:
I wanted to create a hidden files (for configuration etc) by starting the filename with a dot on a Linux system. The following line aborts the program when filename is a std::string starting with a dot:
boost::filesystem::path filename_complete = basepath / filename;
Are there any tricks for that?
You need to use a native path. Read up on native path representations and the name check mechanism in the documentation for "boost/filesystem/path.hpp". HTH, Markus
participants (3)
-
Hagen Möbius
-
Markus Schöpflin
-
Uli Türk