TempFiles (2)




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 Sub Form_Click()
MsgBox GenTempName("D:\Temp") 'change to a valid path
End Sub

Private Function GenTempName(sPath As String)
Dim sPrefix As String
Dim lUnique As Long
Dim sTempFileName As String
If IsEmpty(sPath) Then sPath = "D:\Temp" 'change to a valid path
sPrefix = "fVB"
lUnique = 0
sTempFileName = Space$(100)
GetTempFileName sPath, sPrefix, lUnique, sTempFileName
sTempFileName = Mid$(sTempFileName, 1, InStr(sTempFileName, Chr$(0)) - 1)
GenTempName = sTempFileName
End Function
Pass the full path name in the lpszPath argument.
The lpPrefixString lets you add a three letter prefix to the
beginning of the filename, and wUnique tells Windows to either
create a random file name (0 setting) or use the number you supply.
The lpTempFileName, ofcourse, contains the new temporary filename.
As an example, place the API declaration above in a standard module,
then add thefollowing function

Inputs:sPath

Returns:temporary filename

Assumes:
Note that in order for this function to work properly, you must
pass it a valid path. Otherwise, the GetTempFileName function
returns a 0 and a null parameter as the filename in Windows NT.
In Windows 95 or Windows 98, incorrect paths also return a 0,
and lpTempFileName will not contain the temporary filename.


Generate temporary VB files











( tempfiles2.html )- by Paolo Puglisi - Modifica del 17/12/2023