Share your advanced PureBasic knowledge/code with the community.
-
Trond
- Always Here

- Posts: 7446
- Joined: Mon Sep 22, 2003 6:45 pm
- Location: Norway
Post
by Trond »
Finds a new filename suitable for a temporary file.
Code: Select all
#APPCODE = "myapp"
Procedure.s NewTempFilename()
Protected Temp.s = GetTemporaryDirectory()
Protected C.l
Protected Result.s
For C = 0 To 255
Result = #APPCODE + Str(ElapsedMilliseconds()) + Str(C) + ".tmp"
If FileSize(Result) = -1
ProcedureReturn Result
EndIf
Next
EndProcedure
Procedure FinishTempFilename(Filename.s)
ProcedureReturn DeleteFile(Filename)
EndProcedure
-
c4s
- Addict

- Posts: 1981
- Joined: Thu Nov 01, 2007 5:37 pm
- Location: Germany
Post
by c4s »
A little side note... You get but aren't using the temporary directory so better use the following:
Correct code wrote:Result = Temp + #APPCODE + Str(ElapsedMilliseconds()) + Str(C) + ".tmp"
Better 29 month later than never

If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!