龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VB开发 >

转换长短文件名

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
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->

精彩图集

赞助商链接