windows windows如何将短名称(8.3)解析为全名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2897468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:30:37  来源:igfitidea点击:

How does windows resolves short names (8.3) into full names

javawindows

提问by i3anshee

I have a PC running 64 bit Windows Server 2003. There is a java application which uses cmd file as a launcher. The launcher does this

我有一台运行 64 位 Windows Server 2003 的 PC。有一个使用 cmd 文件作为启动器的 java 应用程序。启动器这样做

SET JAVA_HOME= C:\Progra~1\Java

"%JAVA_HOME%\bin\java" [java program execution line]

Java is installed in C:\Program Files\Java. Since it is a x64 windows it also has C:\Program Files (x86)\ folder.

Java 安装在 C:\Program Files\Java 中。由于它是 x64 窗口,因此它还有 C:\Program Files (x86)\ 文件夹。

Now the actual problem is that from time to time this application fails to start because it fails to find java.

现在实际的问题是,这个应用程序时不时会因为找不到java.lang.

So the question is what windows does to resolve such ambiguity? Based on what it makes decisions about which folder to choose?

所以问题是windows如何解决这种歧义?根据它决定选择哪个文件夹?

采纳答案by Powerlord

The simple answer is that Windows stores both short and long filenames.

简单的答案是 Windows 存储短文件名和长文件名。

It did this back when vfat (on top of FAT16) was introduced with Windows 95, continued in FAT32, and is still aroundin NTFS:

当 vfat(在 FAT16 之上)在 Windows 95 中引入时,它就这样做了,在 FAT32 中继续,并且仍然在 NTFS 中:

When you save a file with a long file name to an NTFS drive, NTFS creates, by default, a second file directory entry with a short file name conforming to the 8.3 convention.

将具有长文件名的文件保存到 NTFS 驱动器时,默认情况下,NTFS 会创建第二个具有符合 8.3 约定的短文件名的文件目录条目。

(You can disable 8.3 names on NTFS).

(您可以在 NTFS 上禁用 8.3 名称)。

Side Note: You can see what the short filenames are in a cmd.exe window by running dir /x(thank to cHaofor pointing this out).

边注:您可以通过运行查看 cmd.exe 窗口中的短文件名dir /x(感谢cHao指出这一点)。

回答by ramirogm

The association between long and short names is made when the directory is created. Windows creates a "short path entry" in the directory that contains the 8.3 name. So the association between the short and long name is permanent and doesn't change unless you modify the directories ( rename, delete, recreate ).

长名称和短名称之间的关联是在创建目录时进行的。Windows 在包含 8.3 名称的目录中创建一个“短路径条目”。因此,短名称和长名称之间的关联是永久性的,除非您修改目录(重命名、删除、重新创建),否则不会更改。

This is an example on my machine ( windows 7 )

这是我机器上的一个例子(windows 7)

C:\>mkdir temp

C:\>cd temp

C:\temp>dir
 El volumen de la unidad C no tiene etiqueta.
 El número de serie del volumen es: 0A74-FE30

 Directorio de C:\temp

24/05/2010  12:14 p.m.    <DIR>          .
24/05/2010  12:14 p.m.    <DIR>          ..
               0 archivos              0 bytes
               2 dirs   6.090.723.328 bytes libres

C:\temp>mkdir "Program Files"

C:\temp>mkdir "Program Files (x86)"

C:\temp>mkdir "Program Files (x86_64)"

C:\temp>dir /x
 El volumen de la unidad C no tiene etiqueta.
 El número de serie del volumen es: 0A74-FE30

 Directorio de C:\temp

24/05/2010  12:15 p.m.    <DIR>                       .
24/05/2010  12:15 p.m.    <DIR>                       ..
24/05/2010  12:14 p.m.    <DIR>          PROGRA~1     Program Files
24/05/2010  12:14 p.m.    <DIR>          PROGRA~2     Program Files (x86)
24/05/2010  12:15 p.m.    <DIR>          PROGRA~3     Program Files (x86_64)
               0 archivos              0 bytes
               5 dirs   6.090.723.328 bytes libres

C:\temp>rmdir "Program Files"

C:\temp>mkdir "Program Files (new)"

C:\temp>dir /x
 El volumen de la unidad C no tiene etiqueta.
 El número de serie del volumen es: 0A74-FE30

 Directorio de C:\temp

24/05/2010  12:15 p.m.    <DIR>                       .
24/05/2010  12:15 p.m.    <DIR>                       ..
24/05/2010  12:15 p.m.    <DIR>          PROGRA~1     Program Files (new)
24/05/2010  12:14 p.m.    <DIR>          PROGRA~2     Program Files (x86)
24/05/2010  12:15 p.m.    <DIR>          PROGRA~3     Program Files (x86_64)
               0 archivos              0 bytes
               5 dirs   6.090.723.328 bytes libres

C:\temp>rmdir "Program Files (x86)"

C:\temp>dir /x
 El volumen de la unidad C no tiene etiqueta.
 El número de serie del volumen es: 0A74-FE30

 Directorio de C:\temp

24/05/2010  12:15 p.m.    <DIR>                       .
24/05/2010  12:15 p.m.    <DIR>                       ..
24/05/2010  12:15 p.m.    <DIR>          PROGRA~1     Program Files (new)
24/05/2010  12:15 p.m.    <DIR>          PROGRA~3     Program Files (x86_64)
               0 archivos              0 bytes
               4 dirs   6.090.723.328 bytes libres

As you can see, the name PROGRA~1 is "reused" when I delete the original directory, and create a new one with a name that, when shortened, matches the "PROGRA" prefix.

正如您所看到的,当我删除原始目录并创建一个新目录时,名称 PROGRA~1 被“重用”,其名称在缩短时与“PROGRA”前缀相匹配。

hth

回答by Stephen C

The gory (patent infested) details are also described in this Wikipedia page.

维基百科页面中还描述了血腥(受专利侵扰)的详细信息。

回答by cHao

Whenever a file is created on an NTFS filesystem, the OS can (and pre Windows 7/2008, usually does) also create a short name for it. It's not required, and the name can actually be anything, but if the regular name isn't already 8.3, the short name is usually the first 6 word-characters of the filename, a tilde (~), and a digit (1 for the first file with those same first chars, 2 for the second, etc), a dot, and the first 3 letters of the extension. (If there's no extension, there's usually no dot either.)

每当在 NTFS 文件系统上创建文件时,操作系统也可以(通常在 Windows 7/2008 之前的系统中)也为其创建短名称。这不是必需的,名称实际上可以是任何名称,但如果常规名称不是 8.3,短名称通常是文件名的前 6 个单词字符、波浪号 (~) 和数字(1 代表具有相同第一个字符的第一个文件,第二个字符为 2,等等)、一个点和扩展名的前 3 个字母。(如果没有扩展名,通常也没有点。)

The number doesn't relate otherwise to the name of the file, meaning "program files" can become "progra~1" or "progra~2" or "progr~50", depending on what other files/dirs in that same location are called and (mostly) when they were made. But once the name's set, it rarely changes unless the file is renamed.

该数字与文件名没有其他关系,这意味着“程序文件”可以变成“progra~1”或“progra~2”或“progr~50”,具体取决于同一位置的其他文件/目录被调用并且(大部分)在它们被制造时被调用。但是一旦设置了名称,除非重命名文件,否则它很少更改。