允许移动到回收站的最长文件路径是多少? [英] What is the longest file path allowed to be moved to Recycle Bin?

查看:38
本文介绍了允许移动到回收站的最长文件路径是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我正在测试允许移动到回收站的最长可用文件路径,我得到了有趣的结果.

For my application I'm testing the longest available file path to be allowed to be moved into the Recycle Bin and I'm getting interesting results.

在 Windows XP 上,最大大小为 259 个字符,即 MAX_PATH 常数减 1.

On Windows XP the maximum size is 259 characters, which is the MAX_PATH constant minus 1.

但在我的 Windows 8.1 Pro 上,允许的最大文件路径大小不知何故似乎是 215 个字符.

But on my Windows 8.1 Pro, that maximum allowed file path size somehow seem to be 215 characters.

所以我很好奇是否有任何官方指导方针?

So I'm curious are there any official guidelines for this?

好的,因为下面的海报要求一个 API,我使用 SHFileOperationFO_DELETEFOF_ALLOWUNDO> 将用户的文件放入回收站.由于 Windows 资源管理器对其删除操作使用完全相同的 API,因此可以通过在 Windows 资源管理器中创建一个长路径然后尝试删除它来轻松测试它.在我的实验中,我可以看到以下内容:

OK, since posters below requested an API, I'm using SHFileOperation with FO_DELETE and FOF_ALLOWUNDO to place a user's file into the Recycle Bin. Since Windows Explorer uses the same exact API for its Delete operation it's easy to test it by making a long path within Windows Explorer and then by trying to delete it. In my experiments I can see the following:

  • Windows XP,如果总路径长度为 259 个字符(在某些版本上,可能是 257 个??),文件/文件夹将被放入回收站.否则,Windows 资源管理器仅提供永久删除它的选项.

  • Windows XP, if the total path length is 259 chars (on some editions, it may be 257??), the file/folder will be placed into the Recycle Bin. Otherwise Windows Explorer offers only an option to permanently delete it.

Windows Vista,此限制为 217 个字符,包括在内.

Windows Vista, this limit is 217 chars, inclusively.

Windows 7 和 8,包含 215 个字符.

Windows 7 and 8, it is 215 chars, inclusively.

所以看起来这个最大限制正在缩小......因此我很好奇,如果这在 MSDN 的某个地方有记录?

So it seems like this maximum limit is shrinking... Thus I was just curious, if this is documented somewhere in MSDN?

推荐答案

回收站内部:

Windows XP

每个驱动器都有自己的驱动器:\RECYCLER\%USER_SID% 目录.此目录包含所有已删除的文件,但文件的名称类似于 DcN.ext,其中 D 是名称的固定部分,c 是驱动器号,N 是索引,ext 是原始文件的扩展名.除了删除的文件,还有一个名为INFO2的数据库文件.

Every drive has its own drive:\RECYCLER\%USER_SID% directory. This directory contains all deleted files but files have names like DcN.ext where D is fixed part of the name, c is drive letter, N is a index and ext is extension of original file. Besides deleted files there is database file named INFO2.

INFO2 文件以标题开头.标题结构:

INFO2 file starts with header. Header structure:

Offset Type  Value
0x0000 DWORD Signature  ; Always 5
0x0004 DWORD Unknown1
0x0008 DWORD Unknown2
0x000C DWORD RecordSize ; Always 0x00000320
0x0010 DWORD Unknown3

记录在头之后连续存储到 INFO2 文件的末尾.记录结构:

Records are stored successively immediately after header to the end of the INFO2 file. Record structure:

Offset Type               Value
0x0000 ANSICHAR[MAX_PATH] OriginalFileNameA ; Ansi string
0x0104 DWORD              Index             ; Associated with *N* from *DcN.ext*
0x0108 DWORD              DriveIndex        ; A: = 0; B: = 1; C: = 2; ...
0x010C FILETIME           DeleteFileTime
0x0114 DWORD              OriginalFileNamePhysicalSize
0x0118 WIDECHAR[MAX_PATH] OriginalFileNameW ; Wide string

Windows Vista 及更高版本

每个驱动器都有自己的驱动器:\$Recycle.Bin\%USER_SID% 目录.该目录包含所有已删除的文件,但现在没有数据库文件.每个删除的文件都与 RB 内的 2 个文件相关联.

Every drive has its own drive:\$Recycle.Bin\%USER_SID% directory. This directory contains all deleted files but now there is no database file. Every deleted file is associated with 2 files inside RB.

第一个文件的名称类似于 $INNNNNN.ext,其中 $I 是名称的固定部分,NNNNNN 由 6 个随机字母组成或数字和 ext 是原始文件的扩展名.

First file has name like $INNNNNN.ext where $I is fixed part of the name, NNNNNN consists of 6 random letters or numbers and ext is extension of original file.

$I 文件结构:

Offset Type               Value
0x0000 DWORD              Signature         ; Always 1
0x0004 DWORD              Unknown1
0x0008 DDWORD             OriginalFileSize
0x0010 FILETIME           DeleteFileTime
0x0018 WIDECHAR[MAX_PATH] OriginalFileNameW ; Wide string

第二个文件的名称类似于 $RNNNNNN.ext,其中 $R 是名称的固定部分,NNNNNN 与 $ 中的相同I file 和 ext 是原始文件的扩展名.$R 文件是删除文件本身.

Second file has name like $RNNNNNN.ext where $R is fixed part of the name, NNNNNN is the same as in $I file and ext is extension of original file. $R file is deleted file itself.

正如您在所有情况下看到的,Windows 将文件名存储在大小为 MAX_PATH 字符的数组中.这就是为什么文件名的长度限制是 MAX_PATH - 1 个字符.

As you see in all cases Windows stores filename in array which has size of MAX_PATH chars. That why the limit of length of filename is MAX_PATH - 1 chars.

Windows 10

Windows 10 有了新版本的 $I 文件结构(不知道是什么更新改变了它):

Windows 10 has a new version of $I file structure (don`t know what update changed it):

Offset Type                          Value
0x0000 DWORD                         Signature         ; Always 2
0x0004 DWORD                         Unknown1
0x0008 DDWORD                        OriginalFileSize
0x0010 FILETIME                      DeleteFileTime
0x0018 DWORD                         OriginalFileNameLen
0x001C WIDECHAR[OriginalFileNameLen] OriginalFileNameW ; Wide string

而且看起来现在 Windows 可以在回收站中存储具有任何路径的任何文件.

这篇关于允许移动到回收站的最长文件路径是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆