Function Reference


_TempFile

Generate a name for a temporary file. The file is guaranteed not to exist yet

#include <File.au3>
_TempFile ( [$sDirectoryName = @TempDir [, $sFilePrefix = "~" [, $sFileExtension = ".tmp" [, $iRandomLength = 7]]]] )

Parameters

$sDirectoryName [optional] Name of directory for filename, defaults to the users %TEMP% directory
$sFilePrefix [optional] Filename prefix, defaults to "~"
$sFileExtension [optional] File extenstion, defaults to ".tmp"
$iRandomLength [optional] Number of characters to use to generate a unique name, defaults to 7

Return Value

Returns a Filename of a temporary file which does not exist

Related

_WinAPI_GetTempFileName

Example

#include <File.au3>
#include <MsgBoxConstants.au3>

; Generate a unique filename in @TempDir
Local $sTempFile_1 = _TempFile()

; Generate a unique filename in the @HomeDrive directory and starting with the "prefix" labelled prefix_
Local $sTempFile_2 = _TempFile(@HomeDrive & "\", "prefix_", ".txt", Default) ; Use the Default keyword to use the default parameters

MsgBox($MB_SYSTEMMODAL, "", "Names suitable for temporary file usage: " & @CRLF & @CRLF & _
        "File 1: " & $sTempFile_1 & @CRLF & _
        "File 2: " & $sTempFile_2)