udfFileCreateTemp
str udfFileCreateTemp (str, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileCreateTemp (strPrefix, strExtension)
strFilenameTemp = FileCreateTemp (strPrefix)
strFilename = strFilenameTemp
If strExtension != "" Then strFilename = ItemReplace (strExtension, -1, strFilenameTemp, ".")
blnResult = FileRename (strFilenameTemp, strFilename)
Return strFilename
;..........................................................................................................................................
; This UDF "udfFileCreateTemp" creates a 0-byte file with unique name in the user's temporary folder
; (as specified by the "TMP" or "TEMP" environment variable).
;
; The prefix string can be set by parameter strPrefix and will be truncated to 3 chars.
; The file extension string can be set by parameter strExtension.
; If strExtension is empty, then the file extension is set to "tmp".
;
; The WinBatch FileCreateTemp function can create maximal 65535 temporary files
; of the form "hexnumber.tmp" from "1.tmp" to "FFFF.tmp".
; One more attempt will create WB error 1653.
;
; Detlev Dalitz.20090521.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strFilename01 = udfFileCreateTemp ("", "")                         ; "...\Temp\C70.tmp
strFilename02 = udfFileCreateTemp ("P", "")                        ; "...\Temp\PC71.tmp"
strFilename03 = udfFileCreateTemp ("Pr", "")                       ; "...\Temp\PrC72.tmp"
strFilename04 = udfFileCreateTemp ("Pre", "")                      ; "...\Temp\PreC73.tmp"
strFilename05 = udfFileCreateTemp ("Prefix", "")                   ; "...\Temp\PreC74.tmp"
strFilename06 = udfFileCreateTemp ("P","t")                        ; "...\Temp\PC75.t"
strFilename07 = udfFileCreateTemp ("", "t")                        ; "...\Temp\C76.t"
strFilename08 = udfFileCreateTemp ("", "tx")                       ; "...\Temp\C77.tx"
strFilename09 = udfFileCreateTemp ("", "txt")                      ; "...\Temp\C78.txt"
strFilename10 = udfFileCreateTemp ("Txt","txt")                    ; "...\Temp\TxtC79.txt"
strFilename11 = udfFileCreateTemp ("Txt","special extension.txt")  ; "...\Temp\TxtC7A.special extension.txt"


; Just a trial to reach the limit.
; At least this will trigger a file create error 1653.
;
;For intI = 1 to 65536 ; 65536 = 0xFFFF + 1.
;   strFilename01 = udfFileCreateTemp ("", "")
;Next

Exit