Reputation: 1515
This is a sample code i have written to check if i am able to create a folder with name length greater than MAX_PATH
-
wstring s = L"D:\\Test";
wstring s2 = L"\\?\D:\\datafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffr700000000000000datafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffr700000000000000datafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffr700000000000000datafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffr700000000000000datafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffr700000000000000";
int ret = CreateDirectoryEx(s.c_str(), s2.c_str(), NULL);
int error = GetLastError();
It did not work, the returned error is ERROR_PATH_NOT_FOUND. Can anyone please tell me whats the problem in the code?
Note: "D:\Test" folder is an existing folder. I am using Windows 7.
Upvotes: 0
Views: 922
Reputation: 33744
need not confuse Maximum file name length (path component) and Maximum path length - see Limits
the Maximum file name length is <= 255 Unicode characters for all file systems
and Maximum path length 32,760 Unicode characters with each path component no more than 255 characters
initial error was by using L"\\?\"
prefix - really it must be L"\\\\?\\"
because c/c++ translate "\\"
to \
- but this already only language specific error.
if fix it - must be error ERROR_INVALID_NAME
(converted from NTSTATUS STATUS_OBJECT_NAME_INVALID
) because path component which you use more than 255 characters
Upvotes: 5
Reputation: 15365
Because the syntax is simply wrong. You have to escape the backslash. So the prefix should be L"\\\\?\\"
.
wstring s2 = L"\\\\?\\D:\\dataff...";
Upvotes: 3
Reputation: 191
Because the path sizes are limited (to 160 caracters I think on W7 but not sure)
Upvotes: -1