Applications Must Delete Files Created with GetTempFileName()

ID Number: Q69753

3.00

WINDOWS

docerr

Summary:

When it is necessary for an application to create a temporary file, it

is highly recommended that the GetTempFileName() function be used to

provide the name for the file. Temporary files created by this method

must be deleted by the application before the application terminates.

Windows will not automatically delete these files on application

termination.

More Information:

The "Note" on page 13 of the "Microsoft Windows User's Guide" version

3.0 manual states:

...some applications may create temporary files. These filenames

generally begin with a tilde character (~) and end with the .TMP

extension.... If you quit Windows as described in the preceding

procedure, any temporary files are automatically deleted....

To a Windows programmer, this note may seem to imply that the

GetTempFileName() API will create a file that will be automatically

deleted when Windows shuts down. This is not true; the application

must delete its temporary files.

If each application destroys all its temporary files as it shuts down,

from the end user's perspective, the files ARE automatically deleted,

because the user does not delete them with the File Manager. However,

it is each application, not Windows, that performs the delete.