Windows如何确定/处理任何给定文件的DOS短名称? [英] How does Windows determine/handle the DOS short name of any given file?

查看:173
本文介绍了Windows如何确定/处理任何给定文件的DOS短名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  alongfilename1.txt< ---首先创建了
沿着文件名3 .txt< ---创建第二个

当我运行 DIR / x 在命令提示符下,我看到这些简称:

  ALONGF〜1.TXT alongfilename1.txt 
ALONGF〜 2.TXT alongfilename3.txt

现在,如果我添加另一个文件:

  alongfilename1.txt 
alongfilename2.txt< ---沿文件名3.txt创建第三个




我看到这个:

  ALONGF〜 1.TXT alongfilename1.txt 
ALONGF〜3.TXT alongfilename2.txt
ALONGF〜2.TXT alongfilename3.txt

好。它似乎是根据我创建文件的日期/时间分配〜#。现在,如果我删除alongfilename1.txt,其他两个文件保留它们的短名称

这是正确的吗?

  ALONGF〜3.TXT alongfilename2.txt 
ALONGF〜2.TXT alongfilename3.txt

何时将该ID(本例中为〜1)释放以用于其他短名称。它会永远吗?

另外,我的机器上的文件有可能是X的短名称,而另一台机器上的同名文件的名字是Y?我特别担心自定义操作使用DOS短名称的安装。



谢谢,伙计们。

解决方案

短文件名是用文件创建的。该算法是这样工作的(通常,但请参阅
$ $ $ code $ counter $ 1
stripped_filename = strip_dots(strip_non_ascii_characters(filename ))
shortfn = first_6_characters(stripped_filename)
while(file_exists(shortfn +〜+ counter +。+ extension)){
递增计数器1
if more数字被添加到计数器,缩短1
/ *例如如果计数器达到9,则采取shortf〜9.txt。试试短〜10.txt下一步* /
}

这意味着一旦文件创建,它将保持其短名称,直到它被删除。



只要文件被删除,短名称可能会再次使用。



如果您移动文件在其他地方,它可能会得到一个新的短名称(例如,你正在移动c:\ somefilewithlongname.txt(c:\somefi〜1.txt)到d:\stuff\somefilewithlongname.txt,如果有d:\stuff\somefileelse.txt(d:\stuff\somefi〜1.txt),被移动的文件的短名称将是somefi〜2.txt)。看起来,短名称只在给定机器上的给定目录中持久。



所以:短文件名将由文件系统生成,通常通过概述的方法以上。假设短文件名不是永久的,因为一台机器上的c:\ longfi〜1.txt可能是c:\ longfilename.txt,而在另一台机器上可能是c:\ longfish_story。文本;另外,当文件被删除时,短名称会立即再次出现。


I have a folder with these files:

alongfilename1.txt <--- created first
alongfilename3.txt <--- created second

When I run DIR /x in command prompt, I see these short names assigned:

ALONGF~1.TXT alongfilename1.txt
ALONGF~2.TXT alongfilename3.txt

Now, if I add another file:

alongfilename1.txt 
alongfilename2.txt <--- created third
alongfilename3.txt

I see this:

ALONGF~1.TXT alongfilename1.txt
ALONGF~3.TXT alongfilename2.txt
ALONGF~2.TXT alongfilename3.txt

Fine. It seems to be assigning the "~#" according to the date/time that I created the file. Is this correct?

Now, if I delete "alongfilename1.txt", the other two files keep their short names.

ALONGF~3.TXT alongfilename2.txt
ALONGF~2.TXT alongfilename3.txt

When will that ID (in this case, ~1) be released for use in another shortname. Will it ever?

Also, is it possible that a file on my machine has a short name of X, whereas the same file has a short name of Y on another machine? I'm particularly concerned for installations whose custom actions utilize DOS short names.

Thanks, guys.

解决方案

The short filename is created with the file. The algorithm works like this (usually, but see moocha's reply):

counter = 1
stripped_filename = strip_dots(strip_non_ascii_characters(filename))
shortfn = first_6_characters(stripped_filename)
while (file_exists(shortfn + "~" + counter + "." + extension)) {
    increment counter by 1
    if more digits are added to counter, shorten shortfn by 1 
    /* e.g. if counter comes to 9 and shortf~9.txt is taken. try short~10.txt next */
}

This means that once the file is created, it will keep its short name until it's deleted.

As soon as the file is deleted, the short name may be used again.

If you move the file somewhere else, it may get a new short name (e.g. you're moving c:\somefilewithlongname.txt ("c:\somefi~1.txt") to d:\stuff\somefilewithlongname.txt, if there's d:\stuff\somefileelse.txt ("d:\stuff\somefi~1.txt"), the short name of the moved file will be somefi~2.txt). It seems that the short name is only persistent within a given directory on a given machine.

So: the short filenames will be generated by the filesystem, usually by the method outlined above. It is better to assume that short filenames are not persistent, as c:\longfi~1.txt on one machine might be "c:\longfilename.txt", whereas on another it might be "c:\longfish_story.txt"; also, when a file is deleted, the short name is immediately available again.

这篇关于Windows如何确定/处理任何给定文件的DOS短名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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