OptionExplicit
PrivateDeclareFunctionOSGetLongPathNameLib"VB5STKIT.DLL"Alias"GetLongPathName"(ByVallpszLongPathAsString,ByVallpszShortPathAsString,ByValcchBufferAsLong)AsLong
PublicDeclareFunctionOSGetShortPathNameLib"kernel32"Alias"GetShortPathNameA"(ByVallpszLongPathAsString,ByVallpszShortPathAsString,ByValcchBufferAsLong)AsLong
FunctionGetLongPathName(ByValstrShortPathAsString)AsString
ConstcchBuffer=300
DimstrLongPathAsString
DimlResultAsLong
OnErrorGoTo0
strLongPath=String(cchBuffer,Chr$(0))
lResult=OSGetLongPathName(strShortPath,strLongPath,cchBuffer)
IflResult=0Then
GetShortPathName=""
Else
GetLongPathName=StripTerminator(strLongPath)
EndIf
EndFunction
PublicFunctionGetShortPathName(ByValstrLongPathAsString)AsString
ConstcchBuffer=300
DimstrShortPathAsString
DimlResultAsLong
OnErrorGoTo0
strShortPath=String(cchBuffer,Chr$(0))
lResult=OSGetShortPathName(strLongPath,strShortPath,cchBuffer)
IflResult=0Then
GetShortPathName=""
Else
GetShortPathName=StripTerminator(strShortPath)
EndIf
EndFunction
'-----------------------------------------------------------
'函數:StripTerminator
'
'返回非零結尾的字符串。典型地,這是一個由WindowsAPI調用返回的字符串。
'
'入口:[strString]-要刪除結束符的字符串
'
'返回:傳遞的字符串減去尾部零以後的值。
'-----------------------------------------------------------
'
PrivateFunctionStripTerminator(ByValstrStringAsString)AsString
DimintZeroPosAsInteger
intZeroPos=InStr(strString,Chr$(0))
IfintZeroPos>0Then
StripTerminator=Left$(strString,intZeroPos-1)
Else
StripTerminator=strString
EndIf
EndFunction->