- What is the longest path to a directory?
- Posted by Norman Bullen on March 29th, 2008
The MSDN documentation for SetCurrentDirectory() says that its argument
can be no longer than MAX_PATH, including a trailing backslash and NUL
character.
The documentation for GetCurrentDirectory() specifies no such limit on
the string returned, suggesting the possibility that a longer string
might be returned.
The documentation for CreateDirectory() says that there is a limit of
248 characters for a "path" without specifying whether a file name must
be included in that length. (In testing, I have been able to create
consisting of directories only that is 253 characters long, including
the drive letter and colon and also the trailing NUL character. I
haven't been able to create a longer path to a directory using just
Windows Explorer and "mkdir" in a command prompt window.) It also says
that the path may be longer when Unicode is used and "\\?\" is prepended.
Note that the "\\?\" syntax is not mentioned in the documentation for
SetCurrentDirectory().
So, my questions are: Is it possible that a string can be returned by
GetCurrentDirectory() that is too long to be passed to
SetCurrentDirectory()? If so, is my only option to parse the result from
GetCurrentDirectory() into shorter strings separated at the backslash
characters?
--
Norm
To reply, change domain to an adult feline.
- Posted by jim clark on April 1st, 2008
This sounds like a documentation omission. You can add \\?\ to pretty much
any path, providing you are using the Unicode version of the function, to
beat the MAX_PATH limit.
MSDN usually says something like: In the ANSI version of this function, the
name is limited to MAX_PATH characters. To extend this limit to 32,767 wide
characters, call the Unicode version of the function and prepend "\\?\" to
the path.
See the section on Maximum Path length at:
http://msdn2.microsoft.com/en-us/lib...47(VS.85).aspx
It does make you wonder what happens if the current directory is > MAX_PATH
and you call the ANSI version of GetCurrentDirectory() ? (I haven't tried
this)
James
"Norman Bullen" <norm@BlackKittenAssociates.com> wrote in message
news:13utgn3lulvqc2b@corp.supernews.com...
- Posted by Alf P. Steinbach on April 1st, 2008
* Norman Bullen:
It used to be that you could use the \\?\ syntax with the md command.
Nowadays you have to use logical drives to create long paths in the command
interpreter.
Probably.
No, that wouldn't help.
Your only practical option is to limit your application to MAX_PATH, same as
Windows Explorer.
The Windows file system is a set of kludges.
Cheers, & hth.,
- Alf
- Posted by Sebastian G. on April 1st, 2008
jim clark wrote:
Wait a moment... isn't \\?\ for ANSI namespaces? And \\.\ for Unicode
namespaces?
- Posted by Norman Bullen on April 2nd, 2008
Alf P. Steinbach wrote:
I guess some more experimentation is in order.
Norm
--
Norm
To reply, change domain to an adult feline.
- Posted by jim clark on April 2nd, 2008
\\?\ is used for Unicode
\\.\ is used for devices
See http://msdn2.microsoft.com/en-us/lib...47(VS.85).aspx
I can understand the device concept (although \dev\device would make even
more sense) but I've never understood why \\?\ was actually required. If
anyone can tell me...
James
"Sebastian G." <seppi@seppig.de> wrote in message
news:65f3gsF2c75vjU1@mid.dfncis.de...
- Posted by Sebastian G. on April 2nd, 2008
jim clark wrote:
OK, my fault: Way around, \\?\ is Unicode and \\.\ is ANSI.
Hm? Both syntaxes refer to \Global in the Windows Namespace Filesystem,
whereas devices reside under the \Device namespace directory. For devices
the name syntax is special, whereas \\?\ only specifies that we want the
Unicode namespace, and \Device\DeviceName refers to the actual device - but
for no apparent reason, these are merged into one name without separation.
That is \\?\\Device\DeviceName should actually be "\\?\ \Device\DeviceName",
or rather \\?\..\Device\DeviceName.
- Posted by Jayapal Chandran on April 3rd, 2008
On Apr 1, 6:43 am, "jim clark" <nospam-j...@ergo.co.uk-nospam> wrote:
where it is used in specifying the path...
- Posted by Norman Bullen on April 3rd, 2008
Jayapal Chandran wrote:
reference is in the documentation for CreateDirectory() at
http://msdn2.microsoft.com/en-us/library/aa363855.aspx
--
Norm
To reply, change domain to an adult feline.