Need a temporary file for your program to use? The 32-bit API has a call that will create a unique file for you in the Windows temporary directory.
Declare
Declare Function OSGetTempPath& Lib "kernel32" Alias "GetTempPathA" (ByVal BufferLength&, ByVal Result$)
Declare Function OSGetTempFilename& Lib "kernel32" Alias "GetTempFileNameA" (ByVal FilePath$, ByVal Prefix$, ByVal wUnique&, ByVal TempFileName$)
Code
Function sGetTempFile(ByRef sPrefix As String)
Dim sFilePath As String
Dim sTempResult As String
Dim lCharCount As Long
Const MAX_RETURN = 3000
sTempResult = Space$(MAX_RETURN)
lCharCount = OSGetTempPath&(MAX_RETURN, sTempResult)
sFilePath = Left$(sTempResult, lCharCount)
sTempResult = Space$(MAX_RETURN)
lCharCount = OSGetTempFilename&(sFilePath, sPrefix, 0, sTempResult)
sGetTempFile = Left$(sTempResult, lCharCount)
End Function
Usage
sTempFile = sGetTempFile(sPrefix:="VBT")
This API call will tag a prefix (up to 3 characters) to the file. This makes it easier for you find, use, or delete your temporary files.
|