C
CSharp
C++
Java
Visual Basic
HTML - CSS
Android
Asp
Asp.Net
Php
Python
JavaScript
SQL
XML
Assembly
ActiveX
API
Code Snippets
Database
Files Directories Drives
Forms
Graphics Games
Multimedia
Strings
Windows and Controls
More...
Visual Basic > Files Directories Drives sample source codes
Visual Basic Code > Create a name for a temporary file
Create a name for a temporary file The following function creates a name for a temporary file which can be used to store temporary data. Private 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 Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long 'Purpose : The FileGetTempName function returns a name of a temporary file. 'Inputs : [sFilePrefix] The prefix of the file name. 'Outputs : Returns the name of the next free temporary file name (and path). 'Notes : The filename is the concatenation of specified path and prefix strings, ' a hexadecimal string formed from a specified integer, and the .TMP extension 'Revisions : Function FileGetTempName(Optional sFilePrefix As String = "TMP") As String Dim sTemp As String * 260, lngLen As Long Static ssTempPath As String If LenB(ssTempPath) = 0 Then 'Get the temporary path lngLen = GetTempPath(260, sTemp) 'strip the rest of the buffer ssTempPath = Left$(sTemp, lngLen) If Right$(ssTempPath, 1) <> "\" Then ssTempPath = ssTempPath & "\" End If End If 'Get a temporary filename lngLen = GetTempFileName(ssTempPath, sFilePrefix, 0, sTemp) 'Remove all the unnecessary chr$(0)'s FileGetTempName = Left$(sTemp, InStr(1, sTemp, Chr$(0)) - 1) End Function
Privacy Policy
|
Contact
|
Advertising
|
Link to Us
|
Directory