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
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
让我们编程来回答这个问题:
首先建立一个窗体,在窗体上加两个TEXT控件,其中第一个TEXT的TEXT属性为“显示命令行参数”,第二个TEXT的TEXT属性为“显示转换后文件名”,再建立一个 commandbutton 控件,其caption属性为“显示”,具体原代码如下:
′-------通用,声明:
Dim dosfilename As String ′声明dos 文件名
Dim longfilename As String ′声明长文件名
′------------
Private Sub Command1_Click()
Text1.Text = dosfilename
Text2.Text = longfilename
End Sub
′--------
Private Sub Form_Load()
dosfilename = Command$() ′从命令行取得参数
longfilename = Dir(dosfilename) ′得到长文件名
End Sub
接着生成EXE文件,然后将一个长文件名的文件图标拖到新生成的EXE文件上去,点击EXE文件的commandbutton 就可以看到转换结果了。
(马 麟)
Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long