Considered the following code:
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
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
Public Function GetTempDir() As String
Dim sBuffer As String
Dim lRetVal As Long
sBuffer = String(255, vbNullChar)
lRetVal = GetTempPath(Len(sBuffer), sBuffer)
If lRetVal Then
GetTempDir = Left$(sBuffer, lRetVal)
End If
End Function
Private Sub Command1_Click()
Dim sBuffer As String
sBuffer = String$(255, vbNullChar)
GetTempFileName GetTempDir(), "aaa", 0, sBuffer
MsgBox sBuffer
End Sub
My question is:
1)Does the code above guarantee to generate a unique filename?
2)This code can only generate file with .tmp extension in user temp directory, how to create a folder with unique name?
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
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
Public Function GetTempDir() As String
Dim sBuffer As String
Dim lRetVal As Long
sBuffer = String(255, vbNullChar)
lRetVal = GetTempPath(Len(sBuffer), sBuffer)
If lRetVal Then
GetTempDir = Left$(sBuffer, lRetVal)
End If
End Function
Private Sub Command1_Click()
Dim sBuffer As String
sBuffer = String$(255, vbNullChar)
GetTempFileName GetTempDir(), "aaa", 0, sBuffer
MsgBox sBuffer
End Sub
My question is:
1)Does the code above guarantee to generate a unique filename?
2)This code can only generate file with .tmp extension in user temp directory, how to create a folder with unique name?