A few months ago I started to write my first multi-platform application. In the hope to be shielded from all kinds of filesystem specific issues, I started to use boost - also for the first time - mainly because of of boost::filesystem.
Interesting to hear from someone who is actually using the boost::filesystem for multi-platform. Personally I have never really understod the reasoning behind the "portability" philosophy behind boost::filesystem. Portability for me means that the code will compile and work the same on different platforms. Strangly enough boost::filesystem works activly against this by enforcing that you use "portable" filenames (unless you specificly turn it off). For me, filenames are input to the application, not a result of it! Why would I want to force a windows user to only enter filenames that are portable?
From a user perspective native_file_string() is portable while string() isn't since it doesn't present the path in a way that the user recognize.
Same thing with wide-character filenames. Why should boost::filesystem::path care if the path it carries is in a std::string or std::wstring? The wide- character filesystem operations can be difficult/impossible to implement on some systems but so are probably other operations. The alternative today is to not use boost::filesystem at all. Don't get me wrong here. I use boost::filesystem in all my applications and I am really happy with it but I also struggle with its limitations. Without wide- character support I probably have to stop using it in a not to distant future.
However - I have found that it doesn't shield me from a LOT of filesystem specific things. In the meantime I was in the need of writing six additional functions that are filesystem specific:
std::string native_file_string(fs::path const&); void copy_file(fs::path const& source_file, fs::path const& target_file); void chmod(fs::path const& filename, bool readonly); bool is_readonly(fs::path const& filename); void rename_file(fs::path const& source_file, fs::path const& target_file); size_t get_file_size(fs::path const& filename);
Add to that the possibility to only iterate over specific files like "*.txt". Only the filsystem knows if "file.TXT" matches "*.txt" so the directory_iterator can't be used for this simple case