★请大家帮写一个VB函数,把长路径转变短路径

来源:百度知道 编辑:UC知道 时间:2024/06/14 16:29:30
请大家帮写一个VB函数,把长路径转变短路径(即DOS路径),如把"C:\Program Files\Internet Explorer\iexplorer.exe"转变为"C:\Progra~1\Intern~1\iexplo~1.exe",对吗?,主要是想用wshshell.run调用运行,
又比如"C:\Program Files\MSN Messenger\msmsgs.exe"该转变成什么呢?
是"C:\Progra~1\MSN Me~1\msmsgs.exe"还是"C:\Progra~1\MSNMess~1\msmsgs.exe"?
+转变有什么要注意的吗?
<VB妮可>转的贴我看不懂,可以解释一下吗?——我是初学者

我转贴的,呵呵.

Option Explicit

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

Private Function ShortPath(ByVal FileName As String) As String
Dim S As String
On Error GoTo exitFunc:
S = String(255, " ")
GetShortPathName FileName, S, 255
ShortPath = Left(S, InStr(S, Chr(0)) - 1)
exitFunc:
End Function

我记得有个路径转换函数吧

Private Function ShortPath(ByVal FileName As String) As String
Dim S As String
On Error GoTo exitFunc:
S = String(255, " ")
GetShortPathName FileName, S, 255
ShortPath = Left(S, InStr(S, Chr(0)) - 1)
exitFunc:
End Function