Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (Byval
lpszPath As String, Byval lpPrefixString As String, Byval wUnique As Long,
Byval TempFileName As String) As Long
Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (Byval
nBufferLength As Long, Byval lpBuffer As String) As Long
Declare Function GetSystemDirectory Lib "Kernel32" Alias "GetSystemDirectoryA"
(Byval lpBuffer As String, Byval nSize As Long) As Long
'



'===============================================================================
===========
' C L A S S "TmpFile"
'===============================================================================
===========
Class TmpFile

Declare Public Function GetSysDir()As String
Declare Public Function TempPath() As String
Declare Public Function IsDriveAvailable(drivNam$) As Variant
Declare Private Function DeleteExtraChars(sSource As String, eChar As String)
As String

Public Function CreateTempFileName(inDir As String) As Variant

On Error Goto ERROR_HANDLE

tName$ = Space$(255)
Prefix$ = "TMP"

inDir = DeleteExtraChars(inDir, "\")

If inDir = "" Then
TMP$ = TempPath()
Else
' inDir must be terminated by an "\"
If Right$(inDir,1) <> "\" Then
inDir = inDir & "\"
End If
' Check if Path exists, else create Path
MakePath(inDir)
End If
TMP$ = inDir
r& = GetTempFileName(TMP$, Prefix$, 0&, tName$)
CreateTempFileName = Left$(tName$, Instr(tName$, Chr$(0)) -1)
Exit Function
ERROR_HANDLE:
CreateTempFileName = "99"
Exit Function
End Function

Public Function TempPath () As String
' Get System Temp Dir
Dim Buffer As String
Buffer = Space$(255)
r& = GetTempPath(Len(Buffer),Buffer)
TempPath = Left$(Buffer, Instr(Buffer, Chr$(0)))

End Function

Public Function GetSysDir()As String
Temp$ = Space(255)
vlen& = GetSystemDirectory(Temp$, Len(Temp$))
Temp$ = Left$(Temp$, vlen&)
GetSysDir = Temp$
End Function


Private Function DeleteExtraChars(sSource As String, eChar As String) As
String

Dim sResult As String
sResult = ""

For i% = 1 To Len(sSource)
If Mid$(sSource,i%,1) = eChar Then
If flag& = 0 Then
sResult = sResult & Mid$(sSource,i%,1)
flag& = 1
End If
Else
sResult = sResult & Mid$(sSource,i%,1)
flag& = 0
DeleteExtraChars = sResult
End If

Next
DeleteExtraChars=sResult
End Function

End Class

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.