# Deleting Outlook 2007 Temp Files using Batch File commands



## pmorris (Dec 30, 1998)

Since Outlook 2007 stores temp files in a randomly generated subfolder (following %userprofile%\Local Settings\Temporary Internet Files\Content.Outlook\), what is a good batch file/DOS command syntax that I can use to delete the folder contents?

Thanks in advance for your help.


----------



## TheOutcaste (Aug 8, 2007)

```
Set _OLKTemp=%userprofile%\Local Settings\Temporary Internet Files\Content.Outlook\
For /F "tokens=*" %%I In ('Dir /b /ad "%_OLKTemp%"') Do RD /Q /S %_OLKTemp%%%I
Del /F /Q %_OLKTemp%*.*
```
HTH

Jerry


----------



## pmorris (Dec 30, 1998)

Jerry, since Outlook 2007 creates randomly-generated characters for the temp folder name, wouldn't OLKtemp in the script create a problem? The OLK temp folders are a product of Outlook 2003, not Outlook 2007.

Could you update your script to account for _%userprofile%\Local Settings\Temporary Internet Files\Content.Outlook\??????_ (where ?????? is the randomly-generated temp folder name)? Thanks.


----------



## TheOutcaste (Aug 8, 2007)

That is exactly what the script does now.
* _OLKTemp* points to *%userprofile%\Local Settings\Temporary Internet Files\Content.Outlook\*
The *For* loop then uses the *DIR* command to read all the random folder names that are contained in the *%userprofile%\Local Settings\Temporary Internet Files\**Content.Outlook\* folder.
The loop variable *%%I* will be just the folder name and will not contain the path, so I used *%_OLKTemp%* to add the path to the folder name so the *RD* command would have the fully qualified path (The *~f* modifier can't be used, as it will use the drive and path of the current working directory).
The *Del* statement then removes any files that are stored directly in the *Content.Outlook* folder. If it never stores files directly in that folder you can remove that line. I don't have 2007, so I couldn't check. If I remember correctly, Outlook 2003 does store files directly in that folder, so I included that just in case.

You can replace *RD /Q /S %_OLKTemp%%%I* with *Echo %%I* and then with *Echo %_OLKTemp%%%I* to test.

HTH

Jerry


----------

