VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 获得Win9X下文件的短文件名
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:8668, 日期:2001-11-20
获得Win9X下文件的短文件名

步骤一

在Form中加入一个FileListBox,一个DirListBox,一个Label.

步骤二

在Form中加入以下代码:

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

Private Sub Dir1_Change()
File1 = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1 = Drive1
End Sub

Private Sub File1_Click()
Label1.Caption = GetShortFileName(Dir1 & "\" & File1)
End Sub

Public Function GetShortFileName(ByVal FileName As String) As String
注释:converts a long file and path name to old DOS format
注释:PARAMETERS
注释: FileName = the path or filename to convert
注释:RETURNS
注释: String = the DOS compatible name for that particular FileName

Dim rc As Long
Dim ShortPath As String
Const PATH_LEN& = 164

注释:get the short filename
ShortPath = String$(PATH_LEN + 1, 0)
rc = GetShortPathName(FileName, ShortPath, PATH_LEN)
GetShortFileName = Left$(ShortPath, rc)
End Function