ecommerce web developer development freelance website designer India
Option Explicit
Usage chose one depending on you needs
sTempFile = fnGetTempPath(sPrefix, sDir)
sTempFile = fnGetTempPath(sPrefix)
sTempFile = fnGetTempPath(, sDir)
sTempFile = fnGetTempPath()
sTempFile = fnGetTempPath

Parms (both are optional)
sPrefix: Use if you want the file name to start with your defined characters. Only first 3 chars are used if ommited file is
named @@@@.tmp
sDir: if you want a temp file in a specfic directory, if omitted the system temp directory is used.

Returns: The name of the empty file created.
_______________________________________________________________________________

' get the directory in the temp enviromental variable
' dir name is returned in lpBuffer
Public Declare Function GetTempDir Lib "kernel32" _
Alias "GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

' get the name and allocate the file
' path
Public Declare Function GetTempFilename Lib "kernel32" _
Alias "GetTempFileNameA" _
(ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long

Private Const MAX_PATH As Long = 256
'
' if path is passed it is used else the temp path is used
' returns temp path & temp file name
' Can be optionaly be passed a filename Prefix
' ----------------------------------------------------------------------
Public Function fnGetTempPath( _
Optional sOptPrefix As String = "", _
Optional sOptDir As String = "") As String
' ----------------------------------------------------------------------
Dim sRoutineID As String

Dim lReturnVal As Long
' be sure variables are long enought
' MAX_PATH is used in API call also
Dim sTempDir As String * MAX_PATH
Dim sTempFilename As String * MAX_PATH

On Error GoTo Handle_Error
sRoutineID = "modGetTempFile fnGetTempPath"

' be sure the string ends with a null char
' or error can result

sOptPrefix = Trim$(sOptPrefix) & vbNullChar

' get the path in the temp enviromental variable
' or use the optional path ( check for ending \)
sOptDir = Trim$(sOptDir)
If Len(sOptDir) < 2 Then
lReturnVal = GetTempDir(MAX_PATH, sTempDir)
Else
If Right$(sOptDir, 1) <> "\" Then
sOptDir = sOptDir & "\"
End If
sTempDir = sOptDir & vbNullChar
End If

' now get and create a temp file in that path
lReturnVal = GetTempFilename(sTempDir, sOptPrefix, 0, sTempFilename)
'return the name of the file
fnGetTempPath = sTempFilename

Exit_Point:
Exit Function

Handle_Error:

MsgBox "Unexpected Error Returned" & vbCrLf _
& "At " & sRoutineID & vbCrLf _
& "Nmbr " & Err.Number & vbCrLf _
& "Desc " & Err.Description & vbCrLf _
& "Srce " & Err.Source & vbCrLf _
& "Time " & Now & vbCrLf _
& "Path " & App.Path, _
16, "You have a Problem!"

fnGetTempPath = ""
Resume Exit_Point
End Function
Get temp-file

901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

Express News India | Freelance ecommerce web development India