views:

657

answers:

3

Hi,

I have a query regarding the directory returned from Path.GetTempPath() function.

It returns "C:\Documents and Settings\USER\Local Settings\Temp" as the directory.

I am saving some temp files there and I am wondering when this folder is cleared, so I know how long they will exist, if it is cleared at all that is.

Is it every time I restart the computer? or is it after a certain amount of time? or space is used up?

A nice easy one for someone to answer for me!

Thanks

A: 

It is only cleared when you clear it.

John Saunders
Downvoter: is my response inaccurate?
John Saunders
+3  A: 

It's never cleared (except by the user when he gets tired of all the files clogging up his machine). If you create a file in there, it's your responsibility to delete it once you're finished with it. It is for temporary files, after all.

Gary McGill
Thanks, I thought it'd be best to check incase it was cleared at some point, because I'm storing some files there in an app and didn't want them to disapear without being told so!
ThePower
@ThePower: You really shouldn't rely on your files remaining in the temp folder over time. If the files are meant to be semi-permanent then use the path returned from Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) instead.
LukeH
+2  A: 

It gets cleared whenever the computer gets "cleaned up". This could be done a number of ways: manually by a user, through the Disk Cleanup tool, etc.

Joseph
So do you think there would be any software installed on company computers that would clean up the folder occasionaly? Just out of interest! :)
ThePower
@ThePower I would hope there wouldn't be software that would periodically clean out the temp folder, unless it was a scheduled task of sorts that uses the already existing cleanup tools that come with windows.
Joseph