GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API
GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API
API Declarations
'Module1 (Declarations)
'Module1 Code:
'*** System Temporary Folder ***
Private Declare Function GetTempPath Lib "kernel32.dll" Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
'*** Temporary File Generation ***
Private Declare Function GetTempFileName Lib "kernel32.dll" Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Rate GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API
(1(1 Vote))
'Module1 Code
Public Function TempPath() As String
Dim sPath As String 'buffer
sPath = String(255, Chr(0)) 'fill buffer
Call GetTempPath(255, sPath) 'call system API
sPath = Replace(sPath, Chr(0), "") 'remove null strips
TempPath = sPath 'return temp path
End Function
'*** Get temporary file path... ***
Public Function TempFile() As String
Dim sPath As String 'buffer
Dim sPrefix As String 'file name prefix
Dim lUnique As Long 'unique number (random)
Dim sTempFile As String 'full temp path
Dim lReturn As Long 'api return
sPath = TempPath() 'get temp path
If sPath = "" Then sPath = "C:\" 'if failed, use "C:\"
sPrefix = "mdi" 'any file name prefix
lUnique = CLng(Int(Rnd * 1024) + 1) 'generate unique number
sTempFile = String(255, Chr(0)) 'fill buffer
lReturn = GetTempFileName(sPath, sPrefix, lUnique, sTempFile)
'get temp file name
sTempFile = Replace(sTempFile, Chr(0), "")
'remove strips
TempFile = sTempFile 'return temp file name
End Function
'Form1 with one command button
'Form1 code:
'*** Test now ***
Private Sub Command1_Click()
MsgBox TempFile(), vbInformation
End Sub
GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API Comments
No comments yet — be the first to post one!
Post a Comment