AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

How can I retrieve the path to the Temp directory?

If you have a project that produces temporary files during runtime, it is good practice to make these files in the official Windows temporary directory.  This directory is usually "c:\windows\temp", although it can vary with different flavours of windows.  You can retrieve the path to the temporary directory by using the following code.


You must put the following code in the declarations section of the project.

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

Public Const MAX_PATH = 260


Public Function GetTmpPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetTempPath(MAX_PATH, strFolder)
If lngResult <> 0 Then
    GetTmpPath = Left(strFolder, InStr(strFolder, _
    Chr(0)) - 1)
    GetTmpPath = ""
End If
End Function


An example of how to use the function:

Call MsgBox("The temp path is " & GetTmpPath, vbInformation)



Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at