Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create folder in temp directory

Status
Not open for further replies.

jack1080

Programmer
Jun 2, 2007
34
MY
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?
 
>Does the code above guarantee to generate a unique filename

Within the folder you are creating it, yes. However this does not guarantee that it is unique on your machine

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top