Getting System Folders Easily via API

Temporary Directory

Well the most liked directory to take up so much space and yet people start deleting files from their Windows Directory (hmmmm....)! So heres another way of retrieving the Temporary Directory:

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_LENGTH = 512

Public Function GetTempDirectory() As String
   Dim s As String
   Dim c As Long
   s = Space$(MAX_LENGTH)
   c = GetTempPath(MAX_LENGTH, s)
   If c > 0 Then
       If c > Len(s) Then
           s = Space$(c + 1)
           c = GetTempPath(MAX_LENGTH, s)
       End If
   End If
   GetTempDirectory = IIf(c > 0, Left$(s, c), "")
End Function


Okay time to wrap things up... if you lazy to cut/copy/paste all the code i've done the work for your convienence. The next part as all the code wrapped in a module so you can easily reference any path you want!

You might also like...

Comments

About the author

Thushan Fernando

Thushan Fernando Australia

Senior Developer working at Readify on cool new technology and platforms.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout