about special folders temporary items

If there are multiple instances of the same application, do they each get a different folder?
When an application exits, is the folder cleaned up, or must the application do it itself?

the lifecycle of the temp folders after the application closes is random. The OS will clean things up when it gets around to it… could be a minute, could be a few hours. If it is important to you that the data never exists upon exiting the app, I’d suggest you delete the contents yourself.

I just ran out of disk space in Windows 10 and it popped up a really helpful tool which gave me options to clean out a bunch of things, including temporary items.

I believe OS X has daily,weekly and monthly cronjobs to clean up temp items but I’m not 100% sure about that.

I’m a little less concerned about life time… What worries me is if the SpecialFolder.Temporary is unique between instances of the same application on the same machine.

SpecialFolder.Temporary appears to be the same folder.

dim f As FolderItem = SpecialFolder.Temporary.Child("ggggggggg.y") TextArea1.Text = f.NativePath

Running that in different builds with different bundle identifiers always yields the same path


This is on Mac, maybe Windows or Linux are different. See http://documentation.xojo.com/index.php/SpecialFolder

I use temporary folders for each instance of my application, but I have to care about them: create with a new name (generally temp0, temp1, temp2…) and then delete it when existing the application, but I must care also about deleting these folders when the application breaks (it means next time I start a new instance).

Temporary folder should be different for each user, but for any given user, it should always be the same. So the answer to your initial question is no, each instance of your app does not get a unique folder.

Understood Tim. Thanks.
I think I was confusing temp with unique as there is such a method in other APIs.
cheers… hmmm… I wonder if there is a process ID that I can get and append to the temp folder path?

Ramon… I indeed have thought about this I clean up before I exit but If I don’t exit gracefully then I must do the clean up on entry.

GetTemporaryFolderItem () will create a unique file.

now if only that were a folder… :slight_smile:

It can be, if you wish. It provides a unique name. How you use it is up to you.

ahh… verstehen.

To be predictably pedantic: it provides a unique name at the time it was called. It is possible that an item with that name is created between the time it was called and the time you go to create the file. This is unlikely to happen in practice unless there is a malicious program trying to exploit the race condition.

My only complaint about this is that OS X has a ridiculous path name (with about 100 gibberish characters) that makes debugging painful - so sometimes I just force the thing into ~/Library/Caches/com.myapp/tempstuff (or similar) so it’s easier to debug and not go hunting for these randomly named folders.

Does anyone know if the Library/Caches folders are ever auto-cleaned by the OS? I think they aren’t…