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?
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.
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
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
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.
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!
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.