dotNet中将长文件名转为DOS短文件名

来源:互联网 发布:淘宝司法拍卖欺诈 编辑:程序博客网 时间:2024/05/17 01:49

首先,需要声明API:

Public Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

调用:

        Dim shortFilePath As String
        shortFilePath = Space(256)
        GetShortPathName(Application.StartupPath, shortFilePath, 256)

些时shortFilePath中存的就是DOS的短文件名了。注意:它是以/0结尾的,要进行字符串连接等操作,一定要去掉结尾符才起作用。

shortFilePath = shortFilePath.Substring(0, shortFilePath.Trim.Length - 1)

这时就可以对shortFilePath 进行字符串连接等操作了。

去掉/0很重要,要不然其后的字符都将视为无效。

另外,以上说到的方法目前不支持纯中文目录名。
 

原创粉丝点击