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?

- 30,738
- 21
- 105
- 131

- 74,180
- 73
- 171
- 204
-
91I've never seen so many different answers to what ought to be a simple question. 199, 255, 256, 257, 260, 'about 30 000', 'approximately 32 000', and 'it depends'. Sure, there are qualifiers, but these can't all be right can they? – MickeyfAgain_BeforeExitOfSO Aug 24 '10 at 14:18
-
7its 255, I know this as I had to build an application to prevent corporate users from reaching this, as it causes issues on our storage servers. – RobertPitt Jan 20 '11 at 21:57
-
2@RobertPitt. You are missing something in there. Quote from MSDN: "the maximum length for a path is MAX_PATH, which is defined as 260 characters" – Michael Olesen Nov 03 '11 at 12:14
-
7@Michael9000. I believe RobertPitt was quoting the filename limit (which is what this question is about), not the path limit. – gdw2 Nov 16 '11 at 16:31
-
wait is the question "filename max" or "full path" max (made up of several filenames/directory names)? – rogerdpack Sep 07 '12 at 15:33
-
8NTFS is NOT limited to MAX_PATH at all, the Windows Shell is limited to MAX_PATH, NTFS max path length is 32k – paulm Aug 28 '13 at 15:17
-
2FYI: `MAX_PATH` is defined in *minwindef.h* for those looking for it. Additionally, there are other useful macros here. – Nicholas Miller Nov 03 '15 at 20:26
-
@paulm: actually I'd be surprised if that were an NTFS-imposed limit. However, certain restrictions in kernel mode necessitate the limitation to approximately 32k `WCHAR` elements. Namely `UNICODE_STRING` is an issue. – 0xC0000022L Oct 19 '18 at 12:44
-
1@rogerdpack seems a lot of those who answered fell into that exact trap. – 0xC0000022L Oct 19 '18 at 12:45
15 Answers
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 for full details.

- 36,492
- 15
- 194
- 265

- 390,455
- 97
- 512
- 589
-
4Here is some more facts that confirms this answer (Windows is normally limited to 260 characters): http://msdn.microsoft.com/en-us/library/system.io.PathTooLongException.aspx and http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx – Michael Olesen Nov 03 '11 at 12:34
-
65Correct for NTFS, not correct for Windows, according to the link you provided: "In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters". The ***total*** path is, for all practical purposes, limited to 259 characters (allowing for the null-terminator). – Lawrence Dol Mar 14 '12 at 06:49
-
9Apparently if you use the "unicode version" of the Windows API file methods, you can get up to 32767 if you prefix pathnames with "\\?\" is taht right? – rogerdpack Sep 07 '12 at 15:32
-
7@rogerdpack: for the full path, yes, but each individual component (subfolder/final-file) has a limit of 255 utf-16 code points. Plus, normal software expect MAX_PATH, so... *boom* :) – snemarch Oct 02 '12 at 23:14
-
1"approximately 32,000 characters" is probably 32768 characters because on computers numbers are usually powers of 2 and 2^15=32768 – Donald Duck Jul 11 '16 at 16:47
-
6In Windows 10 (Version 1607 - Anniversary Update) and Windows Server 2016 you seam to have an option to ignore the MAX_PATH issue by overriding a group policy entry enable NTFS long paths under Computer Configuration -> Admin Templates -> System -> FileSystem: – Steven Mark Ford Nov 11 '16 at 07:58
-
With 260 you should be fine: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath – tedi Feb 02 '18 at 11:13
-
2Downvoted for the absolutely questionable recommendation to stay below `MAX_PATH` ... we're not in the 1980s anymore! – 0xC0000022L Oct 19 '18 at 10:31
-
@DonaldDuck: and you'd be wrong about this. The theoretical maximum is 65535 **Bytes** because that's how `UNICODE_STRING` counts the buffer size. But because we have to divide that by `sizeof(WCHAR)` we get 32767 (the `Length` is always even in `UNICODE_STRING`). And even that is *still* approximate* because internally a name from the Win32 subsystem, aka DOS name, gets expanded. So instead of `C:` you might have `\Device\HarddiskVolume11`. So that expansion literally takes away from the size you can use *from* the Win32 subsystem. – 0xC0000022L Oct 19 '18 at 10:36
-
Sadly people still run piss old servers because IT must not cost anything. @0xC0000022L. Effectively corporates are in the 80s. – Dragas Jul 15 '20 at 07:48
-
@Dragas oh, I know the feeling. Either way, the first released NT had a limit of roundabout 65k Bytes already. What was lacking was meaningful support in the Win32 subsystem. It took extra effort to make your program use the full path length, whereas `MAX_PATH` was the easy way ... – 0xC0000022L Jul 15 '20 at 18:27
-
-
For those that have the same question: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell I have test the poweshell command with administrator priviledges and it works! – Chris P Sep 14 '21 at 09:03
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.

- 1,337
- 1
- 10
- 14
-
22Wrong - the NUL terminator is part of MAX_PATH, which leaves you with a max path of 256 chars (which you won't be able to create because of the individual-component limit of 255). – snemarch Oct 02 '12 at 23:12
-
4"which you won't be able to create because of the individual-component limit of 255" Wrong. We're talking here about max path length, not max individual path components length. Moreover "When using an API to create a directory, the specified path cannot be so long that you cannot append an 8.3 file name (that is, the directory name cannot exceed MAX_PATH minus 12)." – Ludovic Kuty Apr 11 '14 at 10:04
-
This debate only arrises because the low-level api allows creation of filenames 256 chars, on the assumption that the 256 char is a null, but the file becomes inaccessible (hidden) to native applications, so not generally usefull. – Feb 24 '16 at 12:27
-
4@LudovicKuty: *actually* the OP was talking about the **file name length** limitation, not the **path length** (yes, even in the original revision, I checked). And s/he was very specifically referring to NTFS limits and not to the limits of the OS, a particular subsystem or API or framework. – 0xC0000022L Oct 19 '18 at 12:11
-
@0xC0000022L Yes indeed. I misread it in the OP question and focused on the comments which talk about filename length and path length. – Ludovic Kuty Oct 20 '18 at 04:29
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.

- 76,741
- 107
- 159
- 260

- 918
- 9
- 17
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.

- 30,738
- 21
- 105
- 131

- 20,469
- 14
- 82
- 108
-
1
-
I did the exact same on a Windows XP just for giggles. I hit a limit at 200 characters. Then I just created a file with 255 times `w`, deleted that and created a folder with the same name on Windows 7 x64. Now the question is what is the limiting factor here: the NTFS version, the OS or the subsystem or the Win32 API in XP? – 0xC0000022L Oct 19 '18 at 12:07
-
2The 200-character limit seems to be in explorer. Other programs can create longer filenames. This is probably an intentional limit to save the user from him/her-self. :-) – avl_sweden Feb 28 '20 at 07:44
-
No, what you (inadvertedly) checked was the `MAX_PATH` limitation of 260 (259 without the null terminator). Try it again with `C:\ ` as your current directory. – CherryDT Aug 02 '21 at 16:07
-
I made a program which used the unicode API and managed to get a directory depth with 307 characters on Windows XP. – Prof. Falken Dec 10 '21 at 09:47
-
1@Prof.Falken I don't have XP available anymore to check and I'll take your word on that, perhaps you'd prefer a nice game of tic-tac-toe instead? – dove Dec 10 '21 at 09:54
-
-
-
-
-
-
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).

- 1,611
- 13
- 10

- 711
- 5
- 13
-
1https://msdn.microsoft.com/en-us/library/aa365247.aspx?f=255&MSPPError=-2147217396#maxpath – Dercsár Feb 28 '17 at 14:32
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.

- 26,542
- 16
- 152
- 170

- 65,369
- 27
- 142
- 182
-
1Actually, the referenced MSDN article says that *path* is limited to 260 characters but length of *filename* is filesystem dependant (but commonly 255 bytes). However, it's possible to use "Unicode versions [of Windows API functions]" to raise the path limit to 32767 bytes but that limit is reduced by windows internally expanding the required `\\?\ ` prefix at run time to some unspecified length. The path must stay under 32767 bytes after this expansion. – Mikko Rantalainen Feb 28 '18 at 11:14
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.

- 3,912
- 1
- 25
- 34
-
I tried to save a file deep down a folder hierarchy definitely exceeding 260+ chars from command line with vim but was unsuccessful. – panny Feb 10 '13 at 16:38
-
@panny: so Vim's authors have not taken care to implement long path names then. That's not Windows to blame nor the Win32 subsystem nor does it have anything to do with the **file name length** limitation for NTFS the OP asked about. – 0xC0000022L Oct 19 '18 at 12:01
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.

- 30,999
- 61
- 181
- 291
-
Close enough. As I point out in a comment on the accepted answer, it's 32767 `WCHAR` elements. No, it's _not_ "Unicode characters" (check your Unicode terminology: code points, characters etc ...!). – 0xC0000022L Oct 19 '18 at 10:56
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
-
4However the Windows 8 explorer (Win8.1 Preview in my case) isn't working with this limit and it won't accept paths longer than 259 characters. – Sep 11 '13 at 17:23
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.

- 12,315
- 4
- 41
- 45
In Windows 11 (In NTFS drive) is 236 with extension
For testing rename a file with below name and try to add one character more:
1234567890123456789010123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.txt

- 903
- 3
- 10
- 26
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!

- 16,398
- 7
- 76
- 175

- 23
- 1
-
4No - it is 255. The NameLength field in the NTFS $Filename attribute is a byte with no offset; this yields a range of 0-255 – Dominik Weber Aug 24 '10 at 13:44
-
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

- 1,027
- 10
- 12
-
I checked it under Windows 7 with a program that handles long paths correctly. Each individual path segment could take up 255 characters (I used `w`). So what now? – 0xC0000022L Oct 19 '18 at 12:48
-
No, what you (inadvertedly) checked was the `MAX_PATH` limitation of 260 (259 without the null terminator). Try it again with `C:\ ` as your current directory. – CherryDT Aug 02 '21 at 16:06
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.

- 2,652
- 2
- 34
- 65
-
`The system cannot find the path specified.` is not the same as `The specified path, file name, or both are too long.`. I guess you had a typo or something. You get that message if you try to create a file in a path that doesn't exist or if you want to move to a direction that doesn't exist. – Matthias Burger May 14 '19 at 08:40