views:

28753

answers:

10

Quick and simple question which I need the answer to.

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

Many Thanks

+2  A: 

255 characters.

http://en.wikipedia.org/wiki/Filename

warren
+18  A: 

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, you should generally try to limit path lengths to below 260 characters (MAX_PATH) when possible. See http://msdn.microsoft.com/en-us/library/aa365247.aspx for full details.

Adam Rosenfield
+3  A: 

According to MSDN, it's 260 characters. But read the article, it's a bit more complicated.

Kibbee
+1  A: 

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.

svinto
+4  A: 

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.

Alphager
+2  A: 

199 on XP NTFS, i just checked.

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

Is this some other setting limiting this i wonder, try it for yourself.

dove
A: 

Thanks for all the answers.

I've tested this out and found that the answer depends on where you are storing the file. Storing a file in root C allows you the maximum of 255 characters while storing it in a sub folder allows you less.

Again, Thank you
Stephen

GateKiller
Well obviously, because the canonical path of a file in a sub folder includes the root!
Daniel Goldberg
A: 

actually is 256

http://msdn.microsoft.com/en-us/library/ee681827(VS.85).aspx#limits

fane
No - 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
A: 

What is the length of the file name (not considering the entire path as its is limited to 260 in Vista)? I found during testing of our in house application that it was able to upload only files with 172 characters in file name (again not entire path). Please throw some light.

Ankit
A: 

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 a file or directory can be up to 255 characters. When specifying the full path under windows, you need to prefix the path with \?\ to mrk this path as a 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 process- wide setting).

Dominik Weber