NTFS(Windows XP 和 Windows Vista)中的最大文件名长度?

发布于 2024-07-08 14:02:48 字数 74 浏览 11 评论 0原文

我正在设计一个数据库表,它将保存上传文件的文件名。 Windows XP 或 Vista 使用的 NTFS 文件名的最大长度是多少?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

り繁华旳梦境 2024-07-15 14:02:48

文件名的各个组成部分(即路径上的每个子目录和最终文件名)限制为 255 个字符,总路径长度限制为大约 32,000 个字符。

但是,在 Windows 上,您不能超过 MAX_PATH 值(文件为 259 个字符文件夹为 248 个字符)。 请参阅 http://msdn.microsoft.com/en-us/library/aa365247 .aspx 了解完整详细信息。

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.

踏雪无痕 2024-07-15 14:02:48

它有 257 个字符。
准确地说:
NTFS 本身确实规定了数千个字符的最大文件名长度(大约 30,000 个字符)。
但是,Windows 规定路径+文件名的最大长度为 260。 驱动器+文件夹至少占用 3 个字符,因此最终得到 257 个字符。

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.

错爱 2024-07-15 14:02:48

这是框架 4.5 上尝试保存长文件名的文件时显示的“未处理的异常”的内容:

指定的路径、文件名或两者都太长。 完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符。

屏幕截图

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

远山浅 2024-07-15 14:02:48

Windows XP NTFS 上为 199,我刚刚检查过。

这不是理论,而是在我的笔记本电脑上尝试过的结果。 可能会有缓解效果,但从物理上来说,它不会让我让它变得更大。

我想知道是否还有其他设置限制了这一点? 亲自尝试一下。

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.

羁客 2024-07-15 14:02:48

NTFS 中的长度为 255。NTFS $Filename 属性中的 NameLength 字段是一个没有偏移量的字节; 这会产生 0-255 的范围。

文件名本身可以位于不同的“命名空间”中。 到目前为止有:POSIX、WIN32、DOS 和(WIN32DOS - 文件名本身可以是 DOS 名称)。 (由于字符串有长度,因此它可能包含 \0,但这会产生问题并且不在上面的命名空间中。)

因此文件或目录的名称最多可以包含 255 个字符。 Windows下指定完整路径时,需要在路径前加上 >\\?\(或使用 \\?\UNC\server\share 作为 UNC 路径) 将此路径标记为扩展长度路径(约 32k 个字符)。 如果您的路径较长,则必须一路设置工作目录(呃 - 由于进程范围设置而产生副作用)。

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).

橘亓 2024-07-15 14:02:48

根据 MSDN,它是 260 个字符。 它包括 "" - 不可见的终止空字符,因此实际长度是 259。

但是阅读文章,它有点复杂。

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.

沉鱼一梦 2024-07-15 14:02:48

我将其添加到上述批准的答案中。

需要明确的是,人们之所以认为它是 255-260 个字符,是因为这就是 Windows 资源管理器支持的全部内容。 对比这更长的文件名执行文件复制之类的操作会出错。 然而,程序可以读取和写入更长的文件名(这就是资源管理器首先抱怨的长度的方式)。 在这种情况下,微软的“建议修复”是在编写该文件的原始程序中打开该文件并重命名。

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.

多彩岁月 2024-07-15 14:02:48

官方文档的这一部分明确表示 NTFS、exFAT 和 FAT32 为 255 个 Unicode 字符,UDF 为 127 个 Unicode 或 254 个 ASCII 字符。

除此之外,最大路径名长度始终为 32,760 个 Unicode 字符,每个路径组成部分不超过 255 个字符。

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.

余生一个溪 2024-07-15 14:02:48

根据新的Windows SDK文档(8.0),似乎提供了新的路径限制。 有一组新的路径处理函数和 PATHCCH_MAX_CCH 的定义如下:

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

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
錯遇了你 2024-07-15 14:02:48

255 个字符,但完整路径也不应超过此长度。 维基百科上有一个关于此的很好的表格: http://en.wikipedia.org/wiki/Filename

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.

Saygoodbye 2024-07-15 14:02:48

continue

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

眸中客 2024-07-15 14:02:48

238!
我在Win7 32位下用以下bat脚本检查了它:

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

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

实际上是 256,请参阅文件系统功能比较、限制

重复 http://fixunix 上的帖子.com/microsoft-windows/30758-windows-xp-file-name-length-limit.html

“假设我们谈论的是 NTFS 而不是 FAT32,则“255 个字符
对于路径+文件”是资源管理器的限制,而不是文件系统本身。
NTFS 支持最长 32,000 个 Unicode 字符的路径,每个路径
组件最多 255 个字符。

Explorer - 和 Windows API - 将您的字符数限制为 260 个字符
路径,包括驱动器号、冒号、分隔斜杠和
终止空字符。 可以读取更长的路径
Windows 如果您使用 \\"

启动它

如果您阅读了上面的文章,您会发现有第五件事您可以确定:
至少找到一名顽固的计算机用户!

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!

吻泪 2024-07-15 14:02:48

我无法在 WS 2012 Explorer 中创建名称+句点+扩展名长度超过 224 个字符的文件。 不要开枪射杀信使!

在同一服务器的 CMD 中,我无法创建超过 235 字符的名称:

系统找不到指定的路径。

在资源管理器中创建的名称为 224 个字符的文件无法在 Notepad++ 中打开 - 它只是生成一个新文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文