Boost logo

Boost :

From: Yitzhak Sapir (yitzhak.sapir_at_[hidden])
Date: 2006-08-20 05:34:28

The following MSDN article treats the issue of invalid characters
in filenames:

Another article has a similar text (but misses the asterisk in the list):

A simple cpp program also throws on this simple issue. For example,
with a question mark:

#include "windows.h"

int main(int argc, char* argv[])
        HANDLE hf = ::CreateFile("c:\\hi?.c", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, 0);
        if (hf == INVALID_HANDLE_VALUE) {
                std::cout << GetLastError() << std::endl;
        } else {
                std::cout << "Success" << std::endl;
        return 0;

The value returned is ERROR_INVALID_NAME == 123L from winerror.h

However, boost::filesystem::path::windows_name does not have a problem
with a question mark or asterisk. Also, the implementation seems to
attempt to validate any name unless it has these characters whereas it
could use a "valid list" like the unix implementation does. A missing
character from the valid list will probably be an inconvenience but not
as much of a problem as a missing character from the invalid list. My
guess is that an implementation that wishes to support Unicode characters
will need to use the GetStringTypeW or IsCharAlphaNumeric functions to
determine if a letter is an alphanumeric character. Perhaps it is best to
use an implementation that runs "CreateFile(filename, GENERIC_READ, 0, NULL,
OPEN_EXISTING, 0, 0)" and checks the error code for ERROR_INVALID_NAME to
decide if it is a valid filename or not.

Yitzhak Sapir

Boost list run by bdawes at, gregod at, cpdaniel at, john at