info: about maximal path length on Windows

Alexander Belchenko bialix at ukr.net
Wed Jan 31 09:57:30 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Excerpt from MSDN:
===========================================
Maximum Path Length
In the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters. A path is structured
as follows: drive letter, colon, backslash, components separated by backslashes, and a null-terminating character. For
example, the maximum path on the D drive is D:\<256 chars>NUL.

The Unicode versions of several functions permit a maximum path length of 32,767 characters, composed of components up
to 255 characters in length. To specify such a path, use the "\\?\" prefix. For example, "\\?\D:\<path>". To specify
such a UNC path, use the "\\?\UNC\" prefix. For example, "\\?\UNC\<server>\<share>". Note that these prefixes are not
used as part of the path itself. They indicate that the path should be passed to the system with minimal modification.
An implication of this is that you cannot use forward slashes to represent path separators or a period to represent the
current directory.

When using the API to create a directory, the specified path cannot be so long that you could not append an 8.3 file name.

Note that the shell and the file system may have different requirements. It may be possible to create a path with the
API that the shell UI cannot handle.
===========================================

So on Windows NT (2000/XP and so on) bzr could use
very long path names, but it requires
1) always unicode path
2) prefix "\\?\"
3) use only back slashes (bzr tends to always work with forward slashes)

Note: Python support this, but somewhat incomplete (i.e. I cannot do os.path.exists()
but can open file with such prefix for read/write). I think this is related
to "The Unicode versions of several functions...", i.e. only limited set of Win32 API
allow such long paths.

In the past we have one bug report (about adding the file with many uppercase letters)
that we resolve in different way, and permanent problem with selftest.
I'd like to solve problem with selftest in different way -- via using
numbered dirs instead of named dirs.

But anyway, very long filenames is possible to handle, with some limitations,
if we want.

Of course this is likely will not work on Windows 98,
but that another story.

Alexander

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFwGgKzYr338mxwCURAoihAJ40zBUOZP78p9GB9QcaYW1ZcVBtpgCfShol
r0mpn4Yg6sNqm1w0TulTsfE=
=Hk9l
-----END PGP SIGNATURE-----




More information about the bazaar mailing list