AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > VB编程

转换长短文件名

51自学网 http://www.wanshiok.com
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

 

 

 
上一篇:人民币金额转换例程  下一篇:字符串的一些操作