Max path length?

  • Thread starter Thread starter Stan Brown
  • Start date Start date
S

Stan Brown

I have a program compiled under XP but using a compiler not written
for XP; it has a hard-coded limit of 255 characters for a path.

Is that still accurate for XP, or can Windows XP paths be longer? If
so, what is the limit?
 
From one web site page at Microsoft "The full path to the Microsoft Office
2003 document includes the drive letter or server name, and all characters
and folder names up to and including the name of the document. The entire
path cannot be longer than 242 characters in Word, or 218 in Excel."

I found this for Win 9X which I believe holds true for XP "Long file names
are limited to 255 characters in Windows 95. However, the maximum path
length in Windows 95 is 259 characters. The maximum path length represents
the length of the file name, plus the number of characters used to represent
the drive and folder where the file is located. For example, the path length
for the file"



Found this on XP Resource Kit: "

File Names in Windows XP Professional
File names in Windows XP Professional can be up to 255 characters and can
contain spaces, multiple periods, and special characters that are not
allowed in MS-DOS file names. Windows XP Professional makes it possible for
other operating systems to access files that have long names by generating
an MS-DOS-readable (8.3) name for each file. These MS-DOS-readable names
also enable MS-DOS-based and Windows 3.x-based applications to recognize and
load files that have long file names. When a program saves a file on a
computer running Windows XP Professional, both the 8.3 file name and long
file name are retained."
 
I have a program compiled under XP but using a compiler not written
for XP; it has a hard-coded limit of 255 characters for a path.

Is that still accurate for XP, or can Windows XP paths be longer? If
so, what is the limit?

I believe it is now 260 in XP, not enough longer to make it worth
recompiling the program.
--
Tom Porterfield
MS-MVP Windows
http://support.teloep.org

Please post all follow-ups to the newsgroup only.
 
I found this for Win 9X which I believe holds true for XP "Long file names
are limited to 255 characters in Windows 95. However, the maximum path
length in Windows 95 is 259 characters.

Thanks. I couldn't find anything in Windows XP help, or in the first
few dozen hits on Google.
 
Thu, 15 Dec 2005 20:00:17 -0500 from Tom Porterfield
I believe it is now 260 in XP, not enough longer to make it worth
recompiling the program.

A user of the program has unfortunately got a directory structure
with paths longer than that. I couldn't create one myself, but I sent
him a new version of the program that aborts on paths longer than 259
characters, and it did confirm that. I don't know how he created
them, but he's running some version of Windows NT.

So I guess I should no longer trust _MAX_PATH in the C++ compiler,
and I need to recode that section of the program to allocate storage
for paths dynamically.

Has anybody got a recent C++ compiler, one issued since Windows XP?
If so, could you check FILENAME_MAX in <stdio.h> and _MAX_PATH in
<stdlib.h> and tell me the values, just to satisfy my curiosity? (In
MSVC++ 5.0 they're both 260, which is supposed to include the
terminating zero byte.)
 
Stan said:
A user of the program has unfortunately got a directory structure
with paths longer than that. I couldn't create one myself, but I sent
him a new version of the program that aborts on paths longer than 259
characters, and it did confirm that. I don't know how he created
them, but he's running some version of Windows NT.

So I guess I should no longer trust _MAX_PATH in the C++ compiler,
and I need to recode that section of the program to allocate storage
for paths dynamically.

Has anybody got a recent C++ compiler, one issued since Windows XP?
If so, could you check FILENAME_MAX in <stdio.h> and _MAX_PATH in
<stdlib.h> and tell me the values, just to satisfy my curiosity? (In
MSVC++ 5.0 they're both 260, which is supposed to include the
terminating zero byte.)

Looking at the files included with Visual Studio 2005 you have the
following:

stdio.h
#define FILENAME_MAX 260

stdlib.h
#define _MAX_PATH 260 /* max. length of full pathname */
#define _MAX_DRIVE 3 /* max. length of drive component */
#define _MAX_DIR 256 /* max. length of path component */
#define _MAX_FNAME 256 /* max. length of file name component */
#define _MAX_EXT 256 /* max. length of extension component */

Also attempted this on XP and am unable to create files with longer
names using explorer or command prompt. Other programs may not
automatically respect this. We do occasionally see posts in this group
regarding files that are inaccessible because the total file name is
longer than what is supported.
--
Tom Porterfield
MS-MVP Windows
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
Fri, 16 Dec 2005 11:54:34 -0500 from Tom Porterfield
We do occasionally see posts in this group
regarding files that are inaccessible because the total file name is
longer than what is supported.

Good point -- perhaps he's created something in an invalid way.
Thanks for posting the values of the constants: evidently they
haven't changed.
 
Back
Top