Definition of a temporary file
A temporary file is a file that is created to temporarily store information in order to free memory for other purposes, or to act as a safety net to prevent data loss when a program performs certain functions. For example, Word determines automatically where and when it needs to create temporary files. The temporary files only exist during the current session of Word. When Word is shut down in a normal fashion, all temporary files are first closed and then deleted.
Why does Word create temporary files?
Speed
If there is not enough memory available to keep the document with all its edits in memory and still perform manipulations such as sorting, dragging, scrolling, and so on quickly along with any other applications that are running, then Word moves part of its code that is not being used or part of the document that is not being edited from memory to disk. This movement to temporary files on disk frees more memory for text manipulation or storage of the parts of the document that are being actively edited.
Data Integrity
Word uses temporary files as a "safety net" to protect against system errors in its file-saving scheme. By saving to a temporary file first and then renaming the file to the proper name, Word ensures the data integrity of your original file against problems (such as a power failure or lost network connections) that may occur while the file is being written.
Types of temporary files
MS-DOS-Based File
These are standard MS-DOS files.
Document-File-Based File
The difference between this file and a traditional MS-DOS file is that multiple programs can read and write to these files without the original owner knowing about it. Additionally, document files have inherent properties that allow Word to create files and directories within files. At startup, Word creates one temporary (direct) document file called ~wrfxxxx.tmp. You can determine that it is a document file because the initial size is 1,536 bytes. This temporary document file is used to store all OLE objects that belong to unnamed documents, Undo, the Clipboard, and documents whose native formats are not document format (for example, .txt, .rtf, and Word 2.0 documents). Word can open document files using two different modes: transacted and direct. These modes are discussed later in this article.
Transacted Document Files
Transacted files allow Word to open a file, write to it, and have other programs--such as Microsoft Excel--write to it, but still retain the right to restore the file to the state it was in when Word first opened it.
To do this, the document file creates ghost images (typically ~dftxxxx.tmp) of all the changes made to the file after it was opened; if Word keeps all the changes, the contents of ~dftxxxx.tmp merge with the original file, and then saves a complete version of it. Conversely, if Word discards all changes, then ~dftxxxx.tmp is deleted, and the original file does not change. Word opens all of the Word native files using transacted files, which create ghost images in the Temp directory. When you start Word, Normal.dot is typically opened in transacted mode, and a ghost file is created for it called dftxxxx.tmp. FastSave, for example, merges these two files when a save occurs.
Direct
Word uses direct storage when opening the temporary document file and when performing either a Save As or a Full Save (non-FastSave save). This type of file is a low (if any) consumer of memory and does not create a ghost image when created or opened.
Specific files that Word creates
The following tables list some of the specific temporary files that Word creates.
Files typically created when Word is started File name
------------------------------------------------------------------------
MS-DOS-based file (to reserve 4 file handles) 0 bytes ~wrf0000.tmp
MS-DOS-based scratch file 0 bytes ~mfxxxx.tmp
Compound file - transacted 0 bytes ~dftxxxx.tmp
Compound file - direct 1536 bytes ~wrf0001.tmp
(unnamed non-Word/OLE files)
Word recovery files File name
-----------------------------------------------------------------------
Temporary file for AutoRecovery ~wraxxxx.tmp
AutoRecovery AutoRecovery save of <docname>.asd
Other Word temporary files File name
-----------------------------------------------------------------------
Copy of another document ~wrcxxxx.tmp
Word document ~wrdxxxx.tmp
Temp document file ~wrfxxxx.tmp
Dictionary ~wrixxxx.tmp
Clipboard ~wrlxxxx.tmp
Macro ~wrmxxxx.tmp
Word OLE document ~wroxxxx.tmp
Scratch file ~wrsxxxx.tmp
Converted (foreign) document ~wrvxxxx.tmp
A simplified view of the scheme used to save an edited file
Create temp file Create ~wrdxxxx.tmp
Write temp file Save example data to ~wrdxxxx.tmp
Delete original file Delete EXAMPLE.DOC
Move temp to target name Move ~wrdxxxx.tmp to Example.doc
Word gains significant performance speed by placing the temporary file in the same directory as the saved file. If Word placed the temporary file elsewhere, it would have to use the MS-DOS COPY command to move the temporary file from the other directory to the saved location. By leaving the temporary file in the same directory as the saved document file, Word can use the MS-DOS MOVE command to quickly designate the temporary file as the saved document.
When and where Word creates temporary files
The location where Word creates the temporary files is hardcoded information and cannot be edited. Therefore, it is important that NTFS permissions for the user are set accordingly.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
277867 Windows NTFS permissions are required when you run Word on any NTFS partition that has Windows 2000, Windows XP Professional, Windows Server 2003, or Windows Vista installed
In general, Word creates temporary files for the following types of data.
Embedded Word Objects (Temp Directory)
When Word acts as an OLE server program, the embedded Word objects are stored as temporary files in the Temp directory.
OLE 2.0 requires extra drive storage. When you start OLE programs, Word needs to provide copies of the data to the server. It is not unusual for extensive OLE 2.0 usage in a single session of a program to accumulate a large amount of temporary storage on the hard drive.