Wednesday, June 09, 2010

Get temporary folder on PC/MAC

How often do you need to extract files to temporary folder, process them and import back? I do this from time to time, hope you are as well :).
Let's say you have image attached to document and you would like to change it to 32x32 size (obviously you need to change width and height of image in case if it is to big) and attach back to document instead.
I would like to ask about place you usually use to export files. Yes, it is quite easy to extract files to "C:\", easy? right? but not correct, users for sure will not have right for creating files there. Of course I'm pretty sure 95% of you use Environ("Temp") and Environ("Tmp") to determine temporary folder so that's fine, that's I believe only one possible way.
but now question about MAC users, how we can determine their temporary folder? I always use hardcode (yea, shame on me :) ) with path \var\tmp and this approach works fine (at least till this day), but I still can't forget this hardcoded \var\tmp so if anybody know the right way please share it !
Update
here is great link that I was looking for (Thanks to Sasa). Actually main part we need from lss here

Declare Function w32_OSGetSystemTempDirectory Lib "nnotes" Alias "OSGetSystemTempDirectory" ( Byval S As String) As Integer
Declare Function mac_OSGetSystemTempDirectory Lib "NotesLib" Alias "OSGetSystemTempDirectory" ( Byval S As String) As Integer
Declare Function linux_OSGetSystemTempDirectory Lib "libnotes.so" Alias "OSGetSystemTempDirectory" ( Byval S As String) As Integer

Select Case session.Platform
Case "Linux"
s% = linux_OSGetSystemTempDirectory(d)
Case "Macintosh"
s% = mac_OSGetSystemTempDirectory(d)
Case "Windows/32"
s% = w32_OSGetSystemTempDirectory(d)
End Select

1 comment :

Sasa Brkic said...

Andre Guirard wrote a class that will help you to find and use temporary folder used by Notes on Windows, Linux and MacOS. This is what I always use for these tasks as I know I won't have problems with file level authorization. You can get the class at http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/more-on-managing-temporary-files-in-lotusscript

Regards,

Sasa