
The following MSDN article treats the issue of invalid characters in filenames: http://support.microsoft.com/kb/177506/EN-US/ Another article has a similar text (but misses the asterisk in the list): http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/w2000Msg... 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 { ::CloseHandle(hf); 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

Yitzhak Sapir wrote:
this article is obsolete and does not refer to any current version of Windows. Any national characters can be used in a filename. For details see: http://msdn.microsoft.com/library/en-us/fileio/fs/naming_a_file.asp
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.
there is no "valid list" on current versions of Windows. There is only a small number of characters that cannot be used in filenames and that's it. The article you are refering to does not apply to current versions of Windows.
"CreateFile(filename, GENERIC_READ, 0, NULL,
... and trigger implicit conversions from some random 8-bit codepage to internal Unicode representation? I'd much more prefer if programmers use directly Unicode variants of Windows API (eg. CreateFileW ), or at least be aware of conversions they DO NOT control taking place. B.
participants (2)
-
Bronek Kozicki
-
Yitzhak Sapir