Creating a unique temp folder for your files

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Creating a unique temp folder for your files

Post by Mistrel »

This is a neat snippet that will help you find a unique directory for your temporary files. If a directory with the same name exists then it will be enumerated.

Don't forget to remove the folder and its contents when you close your program. :)

Code: Select all

tempdir.s=GetTemporaryDirectory()

Repeat
	dirname.s=tempdir.s+"foldername"+Str(i)
	If FileSize(dirname.s)=-1
		result=CreateDirectory(dirname.s)
		Debug dirname.s ; debug folder name
	EndIf
	i+1
Until result