Windows API

I’m writing a program which needs to clean up the temp files which are in the Temp directory as define by the Temp Environment setting. I don’t want the program to assume that the Temp directory is always C:WindowsTemp. There for I was wondering if there is an API or some other method to determine where is the Temp directory on the users PC. The program is being written in VB 3 Pro and running under Windows95, and all people using this program are running Windows95 as well.

Here’s an answer from my new book about this exact API call:

The GetTempPath API call returns the current temporary directory in use bythe system. This lets you keep your own temporary files confined to aknown location. In addition, you don’t have to guess where you can putthem or have to resort to putting them in the home directory.

The code for the TempDirectory function is listed here:

Public Function TempDirectory() As String   Dim sBuffer As String   Dim iBufLen As Long   Dim iReturn As Long      iBufLen = BUFFER_LENGTH   sBuffer = Space(BUFFER_LENGTH)      iReturn = GetTempPath(iBufLen, sBuffer)   TempDirectory = Left$(sBuffer, iBufLen – 1)End Function
Next, add this API declaration to the declarations section of the module:
Declare Function GetTempPath _   Lib “kernel32” _   Alias “GetTempPathA” _   (ByVal nBufferLength As Long, _   ByVal lpBuffer As String) As Long
That’s all there is to it. Try this line of code somewhere in yourapplication:
Debug.Print TempDirectory
That will probably print something like this line:
Either way, it’s the temporary directory in use by Windows, so you can besure it exists.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job