I'm running Windows 7 in a VirtualBox on an OS X 10.8 host. The host has a shared folder with a file named >>>FILE<<< inside. Apparently, OS X itself has no problem with such file names. Unfortunately, I can't seem to open this files in Windows 7 because of the <s and >s in the name.
In C, this call fails:
CreateFileW(
L"\\\\VBOXSVR\\ft1\\>>>FILE<<<",
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
GetLastError returns ERROR_INVALID_NAME (123). If I change the file name into FILE, I get a valid handle and everything is fine.
Is there a known way in Windows to access those files with invalid characters in their names? Supposing a productive environment with no direct write access to the host's file system.
@jcophenha's answer was on the right track. However, if you read the page that @jcopenha linked to, it states that the \\?\ prefix is for local paths only. You have to use the \\?\UNC\ prefix instead for UNC paths, eg:
L"\\\\?\\UNC\\VBOXSVR\\ft1\\>>>FILE<<<"
The < and > characters are not allowed to be used in a Windows file name. And so that file cannot be opened under Win32.
The naming conventions documentation lists the following reserved characters:
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
Windows differs significantly in this area from *nix systems. On *nix there are typically no such OS enforced limitations on the characters that can be used in a file. As a friend of mine once discovered when he tried to delete a file named * and suffered the most unfortunate consequences.
Now, it is conceivable that these limitations do not apply when using the native API. You could try and open the file with NtCreateFile. That may just work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With