Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Platforms: Win 32s, Win 95/98, Win NT
GetTempPath determines Windows's default Temp directory. The Temp directory is where temporary files made and used by Windows-based programs should be put. Usually this will be the \Temp subdirectory under the Windows directory, but not necessarily. The path of the directory is put into the string variable passed as lpBuffer. The function returns the length of the string returned by the function if it succeeds, or 0 if it fails.
Example:
' Generate a temporary file (path)\api????.TMP, where (path)
' is Windows's temporary file directory and ???? is a randomly assigned unique value.
' Then display the name of the created file on the screen.
Dim temppath As String ' receives name of temporary file path
Dim tempfile As String ' receives name of temporary file
Dim slength As Long ' receives length of string returned for the path
Dim lastfour As Long ' receives hex value of the randomly assigned ????
' Get Windows's temporary file path
temppath = Space(255) ' initialize the buffer to receive the path
slength = GetTempPath(255, temppath) ' read the path name
temppath = Left(temppath, slength) ' extract data from the variable
' Get a uniquely assigned random file
tempfile = Space(255) ' initialize buffer to receive the filename
lastfour = GetTempFileName(temppath, "api", 0, tempfile) ' get a unique temporary file name
' (Note that the file is also created for you in this case.)
tempfile = Left(tempfile, InStr(tempfile, vbNullChar) - 1) ' extract data from the variable
Debug.Print "Temporary filename: "; tempfile
See Also: GetTempFileName
Category: System Information
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Go back to the Windows API Guide home page.
E-mail: rogue953@st-louis.crosswinds.net
This page is at http://www.vbapi.com/ref/g/gettemppath.html