http://blog.csdn.net/wwwdotfa/article/details/8267132
短文件名是dos+fat12/fat16时代的产物,命名规则为8.3
8是指文件名或目录名的主体部分小于等于8个字节
3是指文件名或目录名的主体部分小于等于3个字节
另外其中不能包括空格等非法字符(ysmz4:windowsxp fat32下测试,空格可以出现在子目录名或文件名的后面,在其他地方不行。详细的需要看fatfs参考文档)
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 可以进行准确转换,包括带"."等字符的文件夹