Visual Basic 6 function "sys_get_temp_dir"

Go back

Below you'll find the source for the Visual Basic 6 function sys_get_temp_dir.

Attribute VB_Name = "modSysGetTempDir"
' This function is downloaded from:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

Option Explicit

Private Declare Function GetTempPathA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

' Returns directory path used for temporary files
' Same syntax as the PHP function 'sys_get_temp_dir'
' See also:
' @return   String          The system's temp folder
' @author   Stefan Thoolen <>
Public Function sys_get_temp_dir() As String
    Dim l As Long, ret As String
    ret = String(1024, 0)
    l = GetTempPathA(Len(ret), ret)
    ret = Left(ret, l)
    If Right(ret, 1) <> "\" Then ret = ret & "\"
    sys_get_temp_dir = ret
End Function