file tempfile, introduced by TIP # 210 in Tcl 8.6, creates a temporary file and returns an open read-write channel to it.
file tempfile normally tries to delete the file at the first opportunity, but if varName is given, file tempfile sets that variable to the name of the temporary file and doen't attempt to delete file later. The template is a file name prefix which may include directory components and a file name extension.
Examples
% # <directory><prefix><extension> % file tempfile x /tmp/dingo.txt file5 % set x /tmp/dingo_TaaRfi.txt % # <prefix><extension> % file tempfile x dingo.txt file6 % set x /tmp/dingo_LX7jgP.txt %# <prefix> % file tempfile x txt file9 % set x /tmp/txt_C41OoS %# <extension> % file tempfile x .txt file10 % set x /tmp/tcl_F0Y9on.txt % # Cant use directory by itself as shown below it takes the directory as / and prefix as tmp % file tempfile x /tmp can't create temporary file: permission denied %
AMG: The template filename extension is ignored in Windows [L1 ]. This is a problem because Windows uses extensions to determine how to "open" files.