VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 取得临时文件名
发表评论(0)作者:, 平台:, 阅读:9986, 日期:2000-03-12
取得临时文件名 98-6-30

声明:

Public Const MAX_PATH = 260


Public Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long

Public Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long


代码:

Public Function GetTempFile() As String

Dim lngRet As Long

Dim strBuffer As String, strTempPath As String


'初始化 buffer

strBuffer = String$(MAX_PATH, 0)


'取得临时路径

lngRet = GetTempPath(Len(strBuffer), strBuffer)


'0 错误

If lngRet = 0 Then Exit Function


'去掉尾中的 null

strTempPath = Left$(strBuffer, lngRet)


'初始化 buffer

strBuffer = String$(MAX_PATH, 0)


'取得临时文件名

lngRet = GetTempFileName(strTempPath, "tmp", 0&, strBuffer)


If lngRet = 0 Then Exit Function


lngRet = InStr(1, strBuffer, Chr(0))

If lngRet > 0 Then

GetTempFile = Left$(strBuffer, lngRet - 1)

Else

GetTempFile = strBuffer

End If

End Function