转换长短文件名

2008-02-23 06:52:25来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Option Explicit
Private Declare Function OSGetLongPathName Lib "VB5STKIT.DLL" Alias "GetLongPathName" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Declare Function OSGetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Function GetLongPathName(ByVal strShortPath As String) As String
Const cchBuffer = 300
Dim strLongPath As String
Dim lResult As Long
On Error GoTo 0
strLongPath = String(cchBuffer, Chr$(0))
lResult = OSGetLongPathName(strShortPath, strLongPath, cchBuffer)
If lResult = 0 Then
GetShortPathName = ""
Else
GetLongPathName = StripTerminator(strLongPath)
End If
End Function
Public Function GetShortPathName(ByVal strLongPath As String) As String
Const cchBuffer = 300
Dim strShortPath As String
Dim lResult As Long
On Error GoTo 0
strShortPath = String(cchBuffer, Chr$(0))
lResult = OSGetShortPathName(strLongPath, strShortPath, cchBuffer)
If lResult = 0 Then
GetShortPathName = ""
Else
GetShortPathName = StripTerminator(strShortPath)
End If
End Function
'-----------------------------------------------------------
' 函数: StripTerminator
'
' 返回非零结尾的字符串。典型地,这是一个由 Windows API 调用返回的字符串。
'
' 入口: [strString] - 要删除结束符的字符串
'
' 返回: 传递的字符串减去尾部零以后的值。
'-----------------------------------------------------------
'
Private Function StripTerminator(ByVal strString As String) As String
Dim intZeroPos As Integer
intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function

上一篇: 字符串的一些操作
下一篇: “会报数的计算器”的基本实现

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:在VB程序中通过回收站删除文件

下一篇:建立、改变及重构Access数据库