转换长短文件名
OptionExplicit PrivateDeclareFunctionOSGetLongPathNameLib"VB5STKIT.DLL"Alias"GetLongPathName"(ByVallpszLongPathAsString,ByVallpszShortPathAsString,ByValcchBufferAsLong)AsLong PublicDeclareFunctionOSGetShortPathNameLib"kernel32"Alias"GetShort
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->
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->
- 上一篇:“会报数的计算器”的基本实现
- 下一篇:字符串的一些操作
精彩图集
精彩文章