VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API

by Dipen Anovadia (19 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 19th May 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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



'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

Download this snippet    Add to My Saved Code

GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API Comments

No comments have been posted about GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API. Why not be the first to post a comment about GET THE TEMPORARY FILE NAME WITH PATH IN REAL FORM BY USING WINDOWS API.

Post your comment

Subject:
Message:
0/1000 characters