关于长文件名/短文件名

6 篇文章 0 订阅

短文件名是dos+fat12/fat16时代的产物,命名规则为8.3

8是指文件名或目录名的主体部分小于等于8个字节

3是指文件名或目录名的主体部分小于等于3个字节

另外其中不能包括空格等非法字符


win95+fat32已经支持长文件名,但是同时还是强制使用为长文件名提供8.3短文件名


nt32+ntfs变为可选

ntfs支持unicode文件名,最长255个utf16


长短文件转换的规则,去看msdn


贴一个关于长短转换方法的说明


The technique chosen to auto-generate short names from long names is modeled after Windows NT.  
Auto-generated short names are composed of the basis-name and an optional numeric-tail. 
 
The Basis-Name Generation Algorithm 
 
The basis-name generation algorithm is outlined below.  This is a sample algorithm and serves to 
illustrate how short names can be auto-generated from long names. An implementation should follow 
this basic sequence of steps. 
 
1. The UNICODE name passed to the file system is converted to upper case. 
2. The upper cased UNICODE name is converted to OEM. 
if  (the uppercased UNICODE glyph does not exist as an OEM glyph in the OEM code page) 
 or (the OEM glyph is invalid in an 8.3 name) 

 Replace the glyph to an OEM '_' (underscore) character. 
 Set a "lossy conversion" flag. 

3. Strip all leading and embedded spaces from the long name. 
4. Strip all leading periods from the long name. 
5. While  (not at end of the long name) 
 and (char is not a period) 
 and (total chars copied < 8) 

 Copy characters into primary portion of the basis name 

6. Insert a dot at the end of the primary components of the basis-name iff the basis name has an 
extension after the last period in the name. 
7. Scan for the last embedded period in the long name. 
If (the last embedded period was found) 

 While  (not at end of the long name) 
  and (total chars copied < 3) 
 { 
  Copy characters into extension portion of the basis name 
 } 

Proceed to numeric-tail generation. 
 
The Numeric-Tail Generation Algorithm 
 
 If   (a "lossy conversion" was not flagged) 
 and (the long name fits within the 8.3 naming conventions) 
 and (the basis-name does not collide with any existing short name) 

 The short name is only the basis-name without the numeric tail. 

else 

 Insert a numeric-tail "~n" to the end of the primary name such that the value of the "~n" is 
chosen so that the  
 name thus formed does not collide with any existing short name and that the primary name does 
not exceed eight  characters in length. 

The "~n" string can range from "~1" to "~999999".  The number "n" is chosen so that it is the next 
number in a sequence of files with similar basis-names.  For example, assume the following short 
names existed: LETTER~1.DOC and LETTER~2.DOC.  As expected, the next auto-generated name 
of name of this type would be LETTER~3.DOC.  Assume the following short names existed: 
LETTER~1.DOC, LETTER~3.DOC.  Again, the next auto-generated name of name of this type 
would be LETTER~2.DOC.  However, one absolutely cannot count on this behavior.  In a directory 
with a very large mix of names of this type, the selection algorithm is optimized for speed and may 
select another "n" based on the characteristics of short names that end in "~n" and have similar leading 
name patterns.


相关win32 api

GetShortPathName 可以进行一般转换

但是此api是95时代的,所以有些问题,如带"."的文件夹,不能正常转换

另外 “\\?\”加上此前缀可以绕过RtlDosPathNameToNtPathName_U修正


FindFirstFile 可以进行准确转换,包括带"."等字符的文件夹

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值