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:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

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: http://www.php.net/manual/en/function.sys-get-temp-dir.php
' @return   String          The system's temp folder
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
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