Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As LongLong,装载到lpszShortPath缓冲区的字符数量。如lpszShortPath的长度不足,不能容下文件名,就返回需要的缓冲区长度lpszLongPath ---  String,指定欲获取短路径名的那个文件的名字。可以是个完整路径,或者由当前目录决定  lpszShortPath --  String,指定一个缓冲区,用于装载文件的短路径和文件名  cchBuffer ------  Long,lpszShortPath缓冲区长度

解决方案 »

  1.   

    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
    Public Function GetShortPath(strFileName As String) As String
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim lngRes As Long, strPath As String
        'Create a buffer
        strPath = String$(165, 0)
        'retrieve the short pathname
        lngRes = GetShortPathName(strFileName, strPath, 164)
        'remove all unnecessary chr$(0)'s
        GetShortPath = Left$(strPath, lngRes)
    End Function
    Private Sub Form_Load()
        MsgBox GetShortPath("c:\Program Files\")
    End Sub