Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Get unique temporary file name


How To ... Get unique temporary file name


Private Const MAX_FILENAME_LEN = 256

Private Const UNIQUE_NAME = &H0

Private Declare Function GetTempFileNameA Lib "kernel32" ( ByVal _
  lpszPath As String , ByVal lpPrefixString As String , ByVal wUnique _
   As Long , ByVal lpTempFileName As String ) As Long

Public Function GetTempFileName() As String
  Dim s As String
  Dim s2 As String

 s2 = GetTempPath
 s = Space(Len(s2) + MAX_FILENAME_LEN)
  Call GetTempFileNameA(s2, App.EXEName, UNIQUE_NAME, s)
 GetTempFileName = Left$(s, InStr(s, Chr $(0)) - 1)
End Function