A few years ago I remember a small little Code Project project about a Windows Disk Cleanup component that would cleanup VC6 files. I had always meant to look into that for VS2005 when I had the time.
Well, I had a look at the interfaces that the the Disk Cleanup applet uses and it turns out you can add cleanup items to Disk Cleanup without writing a single line of code. There is a “fallback” cleanup COM component (DataDrivenCleaner) that you can reuse for situations where cleanup can be defined by a directory and/or set of files/wild-cards. Visual Studio 2005 fits this criteria quite nicely; so I whipped together a few registry entries that adds an item to Disk Clean to cleanup select Visual Studio intermediate files older than 30 days. I exported the entries into the attached file (zipped). The contents are as follows:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Visual Studio 2005]
“Display”=“Visual Studio 2005 Intermediate Files.”
“Description”=“Clean up Visual Studio project build files older than 30 days.”
Most items are pretty self-explanatory. Both IconPath and Folder are REG_EXPAND_SZ value types, so the export shows them as hex bytes here. When merged with the registry you’ll see IconPath: “explorer.exe,13″, which just sets the item’s icon to the folder icon; and Folder: “%USERPROFILE%\My Documents\Visual Studio 2005\Projects\”. Flags is set to 1 to recurse subdirectories. And LastAccess = 1e means only files older than 30 (hex 0x1e) days will be cleaned.
So, basically, this will recurse the Visual Studio projects directory deleting files matching the FileList wild-cards (in this case *.obj, *.pch, *.ilk, vc80.pdb, vc80.idb, and buildlog.htm) and are older than 30 days. I purposely didn’t add *.exe *.pdb because I often have files of these times that aren’t with the Debug or Release directory of a project.
Handy if you have a scheduled cleanup (e.g. you run cleanup a hour before you disk defrag–no point in defragging a bunch of intermediate files…).