Bug #7822
closed
Dir.mkdir can't handle long Windows Unicode paths (\\?\UNC\)
Added by shyxormz (Patrick Pokatilo) almost 12 years ago.
Updated over 10 years ago.
Description
Code:
Dir.mkdir "//?/C:/" + "test" * 100
What I expected:
Ruby will create directory //?/C:/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest, judging from http://msdn.microsoft.com/en-us/library/aa365247.aspx
What happened on the second call:
Errno::ENOENT: No such file or directory - //?/C:/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
from (irb):6:in `mkdir'
- Subject changed from Dir.mkdir can't handle long Windows Unicode paths (\\?\UNC\) to Dir.mkdir can't handle long Windows Unicode paths (\\?\UNC\)
- Status changed from Open to Assigned
- Assignee set to usa (Usaku NAKAMURA)
The linked article mentions that each component (individual folder in the path) can have a maximum of 255 characters.
The following works:
Dir.mkdir "\\\\?\\C:\\#{'t'*255}"
Dir.mkdir "\\\\?\\C:\\#{'t'*255}\\#{'t'*255}"
However, there is a general Ruby file issue related to this: Windows does not allow forward slashes for Win32 File Namespaces (\\?\ paths). Thus these paths cannot be used with any methods that use File::SEPARATOR, such as File.join since File::SEPARATOR is '/' on Windows.
(1) Windows has the limitation about the length of each directory name.
It's 255 characters.
So, even if with using UNC name, you cannot make such directory, Patrick.
(2) Yes, you are right, Eric.
Only when using "\\?\", Windows does not recognize "/" as the separator
(the document which Patrick mentioned says so.)
So, use "\" as the separator when using "\\?\" for the time being.
I would recommend that this bug be closed. However, I have not found any feature requests for better support of "\\?\". Is it worth submitting one or would this be better handled with a gem?
- Related to Bug #7821: FileUtils.mkdir_p fails on Windows Unicode paths (\\?\UNC\) if dir already exists added
- Status changed from Assigned to Rejected
After all, the user using special form like "\?" should know the meaning and effect,
so ruby doesn't ought to support it.
Of course, if there is a good patch, I my accept it.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0