Maximum filename length in NTFS (Windows XP and Windows Vista)?

Windows VistaWindows XpNtfsFilenamesName Length

Windows Vista Problem Overview


I'm designing a database table which will hold filenames of uploaded files. What is the maximum length of a filename in NTFS as used by Windows XP or Vista?

Windows Vista Solutions


Solution 1 - Windows Vista

Individual components of a filename (i.e. each subdirectory along the path, and the final filename) are limited to 255 characters, and the total path length is limited to approximately 32,000 characters.

However, on Windows, you can't exceed MAX_PATH value (259 characters for files, 248 for folders). See http://msdn.microsoft.com/en-us/library/aa365247.aspx">http://msdn.microsoft.com/en-us/library/aa365247.aspx</a> for full details.

Solution 2 - Windows Vista

It's 257 characters. To be precise: NTFS itself does impose a maximum filename-length of several thousand characters (around 30'000 something). However, Windows imposes a 260 maximum length for the Path+Filename. The drive+folder takes up at least 3 characters, so you end up with 257.

Solution 3 - Windows Vista

This is what the "Unhandled exception" says on framework 4.5 when trying to save a file with a long filename:

> The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

screenshot

Solution 4 - Windows Vista

199 on Windows XP NTFS, I just checked.

This is not theory but from just trying on my laptop. There may be mitigating effects, but it physically won't let me make it bigger.

Is there some other setting limiting this, I wonder? Try it for yourself.

Solution 5 - Windows Vista

The length in NTFS is 255. The NameLength field in the NTFS $Filename attribute is a byte with no offset; this yields a range of 0-255.

The file name iself can be in different "namespaces". So far there are: POSIX, WIN32, DOS and (WIN32DOS - when a filename can be natively a DOS name). (Since the string has a length, it could contain \0 but that would yield to problems and is not in the namespaces above.)

Thus the name of a file or directory can be up to 255 characters. When specifying the full path under Windows, you need to prefix the path with \\?\ (or use \\?\UNC\server\share for UNC paths) to mark this path as an extended-length one (~32k characters). If your path is longer, you will have to set your working directory along the way (ugh - side effects due to the process-wide setting).

Solution 6 - Windows Vista

According to MSDN, it's 260 characters. It includes "<NUL>" -the invisible terminating null character, so the actual length is 259.

But read the article, it's a bit more complicated.

Solution 7 - Windows Vista

Solution 8 - Windows Vista

I'm adding this to the above approved answer.

TO BE CLEAR, the reason people believe it to be 255-260 characters is because that is all that Windows Explorer supports. It will error out doing something like a file copy on filenames longer than that. However, a program can read and write much longer filenames (which is how you get to lengths that Explorer complains about in the first place). Microsoft's "recommended fix" in situations like this is to open the file in the original program that wrote it and rename it.

Solution 9 - Windows Vista

This part of the official documentation says clearly that it’s 255 Unicode characters for NTFS, exFAT and FAT32, and 127 Unicode or 254 ASCII characters for UDF.

Apart from that, the maximum path name length is always 32,760 Unicode characters, with each path component no more than 255 characters.

Solution 10 - Windows Vista

According to the new Windows SDK documentation (8.0) it seems that a new path limit is provided. There is a new set of path handling functions and an definition of PATHCCH_MAX_CCH like follows:

// max # of characters we support using the "\\?\" syntax
// (0x7FFF + 1 for NULL terminator)
#define PATHCCH_MAX_CCH             0x8000

Solution 11 - Windows Vista

255 chars, though the complete path should not be longer than that as well. There is a nice table over at Wikipedia about this: http://en.wikipedia.org/wiki/Filename.

Solution 12 - Windows Vista

Actually it is 256, see File System Functionality Comparison, Limits.

To repeat a post on http://fixunix.com/microsoft-windows/30758-windows-xp-file-name-length-limit.html

>"Assuming we're talking about NTFS and not FAT32, the "255 characters for path+file" is a limitation of Explorer, not the filesystem itself. NTFS supports paths up to 32,000 Unicode characters long, with each component up to 255 characters. > >Explorer -and the Windows API- limits you to 260 characters for the path, which include drive letter, colon, separating slashes and a terminating null character. It's possible to read a longer path in Windows if you start it with a \\"

If you read the above posts you'll see there is a 5th thing you can be certain of: Finding at least one obstinate computer user!

Solution 13 - Windows Vista

238! I checked it under Win7 32 bit with the following bat script:

set "fname="
for /l %%i in (1, 1, 27) do @call :setname
@echo %fname%
for /l %%i in (1, 1, 100) do @call :check
goto :EOF
:setname
set "fname=%fname%_123456789"
goto :EOF
:check
set "fname=%fname:~0,-1%"
@echo xx>%fname%
if not exist %fname% goto :eof
dir /b
pause
goto :EOF

Solution 14 - Windows Vista

I cannot create a file with the name+period+extnesion in WS 2012 Explorer longer than 224 characters. Don't shoot the messenger!

In the CMD of the same server I cannot create a longer than 235 character name:

> The system cannot find the path specified.

The file with a 224 character name created in the Explorer cannot be opened in Notepad++ - it just comes up with a new file instead.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGateKillerView Question on Stackoverflow
Solution 1 - Windows VistaAdam RosenfieldView Answer on Stackoverflow
Solution 2 - Windows VistaAlphagerView Answer on Stackoverflow
Solution 3 - Windows VistaSturmCoderView Answer on Stackoverflow
Solution 4 - Windows VistadoveView Answer on Stackoverflow
Solution 5 - Windows VistaDominik WeberView Answer on Stackoverflow
Solution 6 - Windows VistaKibbeeView Answer on Stackoverflow
Solution 7 - Windows VistawarrenView Answer on Stackoverflow
Solution 8 - Windows Vistastd''OrgnlDaveView Answer on Stackoverflow
Solution 9 - Windows VistacawView Answer on Stackoverflow
Solution 10 - Windows Vistauser1798386View Answer on Stackoverflow
Solution 11 - Windows VistaSvante SvensonView Answer on Stackoverflow
Solution 12 - Windows VistafaneView Answer on Stackoverflow
Solution 13 - Windows VistaSzBView Answer on Stackoverflow
Solution 14 - Windows VistaajehView Answer on Stackoverflow