WEB开发网
开发学院WEB开发综合 转换长短文件名 阅读

转换长短文件名

 2006-02-27 11:51:24 来源:WEB开发网   
核心提示:OptionExplicitPRivateDeclareFunctionOSGetLongPathNameLib"VB5STKIT.DLL"Alias"GetLongPathName"(ByVallpszLongPathAsString,ByVallpszShortPathAsS
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->

Tags:转换 长短 文件名

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接