| I recently read somewhere, wish I remembered where, that "it's nearly impossible to create any robust application without the use of Temp files." I have to add to that: "IT managers wish all of the apps that created temp files would be coded more professionally." Sure, drive space is cheap, but they think it's annoying to go to a client's temp folder and see hundreds of files with dates back to the Nixon administration, and with obscure file names not using the traditional *.tmp extension that make you fear deleting them for what they *may* be all about. Or worse, to find temp files that were not placed in the Temp folder, where they can be easily deleted in one pass, but rather added to the app folder (and added and added and added). In our apps, let's do the right thing. Use the computer's Temp folder to hold temporary files. Finding that location is easy, just paste the following into a declarations section: Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _ (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long And call it with a routine such as: Public Property Get TempPathLocation() As String Dim sBuffer As String * 255 If GetTempPath(255&, sBuffer) <> 0 Then TempPathLocation = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1) Else TempPathLocation = "" End If End Property This routine gets the computer's established Temp folder. If none has been established for the machine it returns "" which could be interpreted as the current directory. If you want to be real nice to the IT guys and have them not shoot down your next project, set your code to create a temp folder within the app.path if the routine returns the current directory (and nicely remind the company to create Temp folders on their machines). Now that you know where to put files, remember to remove them when you're done with them. If you allow multiple instances of your app and dynamically create temp files using the traditional sFilename = "XYZ" & format(now, "hhnn") & ".tmp" hold a properly scoped variable of the location and sFileName and Kill the file when you are through with it. |
.Temp files |
Express News India | Freelance ecommerce web development India