Click here to Skip to main content
Licence 
First Posted 29 Feb 2000
Views 239,499
Downloads 2,442
Bookmarked 85 times

A Utility to Clean Up Compiler Temp Files

By | 24 Dec 2002 | Article
A shell extension that deletes compiler temp and intermediate files.

 [DirClean menu items - 9K]

Recently at work, I was talking with a coworker about cool little utilities that we wished we had. He mentioned an idea for a shell extension that would remove all intermediate compiler files (such as *.obj) from a directory (and recurse subdirectories, naturally). That sounded pretty neat, and since he was in the middle of writing up a different cool program, I decided to get cracking on the clean-up utility and see what I could do.

I came up with this little app, DirClean. It's a shell extension that appears on the context menu of directories, and has a "Clean up temp files" command that will remove intermediate compiler files from the selected directory and its subdirectories. By default, the files are put in the Recycle Bin, but you can configure DirClean to just delete the files instead. DirClean uses the SHFileOperation function to delete files, so if there are a lot of files to delete, you'll see the familiar flying-paper progress dialog.

DirClean has both ANSI and Unicode versions. It was written with VC 6 SP 3, and tested on Win 98 and Win 2000.

The "DirClean options" menu item brings up the DirClean options dialog:

 [DirClean options - 9K]

The settings here should be self-explanatory. I don't do any checking of the wildcards you enter, so you probably don't want to enter "*.*" ;) The settings are saved in HKEY_CURRENT_USER, so each user has his own settings.

Note that you can override the "Send files to the Recycle Bin" setting by holding down the Shift key when clicking "Clean up temp files." Holding in Shift will immediately delete files if you have the option set to send files to the Recycle Bin, and vice versa.

Important note for VS.NET users

On the NT-based OSes, the way that the shell handles extensions of more than 3 characters will cause problems for C# projects. The default behavior of the shell makes the wildcard *.res match .RESX files (it only compares the first three characters), and deleting the .RESX files will delete some resource information.

So, to avoid deleting those files, you can either remove *.res from the list of files to delete, or go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem, and set the DWORD value Win95TruncatedExtensions to 0, then restart your computer. See KB article Q164351 for more info on this feature.

History

Oct 28, 2001 - Default list of wildcards updated.
Dec 25, 2002 - Added note about the Win95TruncatedExtensions registry entry.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Michael Dunn

Software Developer (Senior)
VMware
United States United States

Member

Michael lives in sunny Mountain View, California. He started programming with an Apple //e in 4th grade, graduated from UCLA with a math degree in 1994, and immediately landed a job as a QA engineer at Symantec, working on the Norton AntiVirus team. He pretty much taught himself Windows and MFC programming, and in 1999 he designed and coded a new interface for Norton AntiVirus 2000.
Mike has been a a developer at Napster and at his own lil' startup, Zabersoft, a development company he co-founded with offices in Los Angeles and Odense, Denmark. Mike is now a senior engineer at VMware.

He also enjoys his hobbies of playing pinball, bike riding, photography, and Domion on Friday nights (current favorite combo: Village + double Pirate Ship). He would get his own snooker table too if they weren't so darn big! He is also sad that he's forgotten the languages he's studied: French, Mandarin Chinese, and Japanese.
 
Mike was a VC MVP from 2005 to 2009.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralFinding a directory Pinmemberseteelle5:00 16 Sep '09  
Generalfix for *.resx and other long extensions Pinmemberedger23:11 16 Sep '08  
GeneralIssue: C# *.resx files mistakenly deleted PinmvpJeffrey Walton3:58 15 Jul '08  
GeneralExcellent, except for one minor problem Pinmemberfrwa10:33 7 Apr '08  
GeneralVista / VS2005 PinmemberKevin Gutteridge4:07 30 Jul '07  
Just love this utility but like everything in my life at the moment it suffers some problems re-compiling. Fixes below...
 

File: DirClean.def
 
EXPORTS
DllCanUnloadNow @1 PRIVATE
DllGetClassObject @2 PRIVATE
DllRegisterServer @3 PRIVATE
DllUnregisterServer @4 PRIVATE
 
Change to.....
 
EXPORTS
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
 
(Remove the ordinal number)
 

File: DirCleanShlExt.h
 
Add
 
struct __declspec(uuid("000214e4-0000-0000-c000-000000000046")) IContextMenu;
 
Before the class declaration.
 

 
File: CShellFileOp.cpp
 
BOOL CShellFileOp::Go ( BOOL* lpbOperationStarted,
int* lpnAPIReturn /*=NULL*/,
BOOL* lpbAnyOperationsAborted /*=NULL*/ )
{
......
 
FillSzzBuffer ( szzSourceFiles, m_lcstrSourceFiles );
 
if ( m_rFOS.wFunc != FO_DELETE )
{
FillSzzBuffer ( szzDestFiles, m_lcstrDestFiles );
}
 
......
}
 

Change to.....
 

BOOL CShellFileOp::Go ( BOOL* lpbOperationStarted,
int* lpnAPIReturn /*=NULL*/,
BOOL* lpbAnyOperationsAborted /*=NULL*/ )
{
......
 
FillSzzBuffer ( szzSourceFiles, dwSourceBufferSize, m_lcstrSourceFiles );
 
if ( m_rFOS.wFunc != FO_DELETE )
{
FillSzzBuffer ( szzDestFiles, dwDestBufferSize, m_lcstrDestFiles );
}
 
......
}
 

void CShellFileOp::FillSzzBuffer ( TCHAR* pBuffer, const CStringList& list )
{
......
 
_tcscpy ( pCurrPos, (LPCTSTR) cstr );
 
......
}
 

Change to.....
 

void CShellFileOp::FillSzzBuffer( TCHAR* pBuffer, size_t stDstSize, const CStringList& list )
{
......
 
strcpy_s( pCurrPos, (stDstSize - 1), (LPCTSTR)cstr );
 
......
}
 

Also change the function declaration in CShellFileOp.h
 

File: DirClean.cpp
 
STDAPI DllRegisterServer(void)
{
......
lRet = reg.SetValue ( _T("DirClean Shell Extension"),
_T("{BA06A5A0-BDE3-11D3-BE82-0050DA63C294}") );
......
}
 

Change to.....
 
STDAPI DllRegisterServer(void)
{
......
lRet = reg.SetStringValue ( _T("DirClean Shell Extension"),
_T("{BA06A5A0-BDE3-11D3-BE82-0050DA63C294}") );
......
}
 

Seems to be working a treat!
 
Regards,
Kevin.
 

 


GeneralKudos and Small Suggestion PinmemberJeffrey Walton9:33 8 Jun '07  
GeneralRe: Kudos and Small Suggestion PinmvpMichael Dunn19:20 9 Jun '07  
GeneralThe .resx registry fix doesn't work on my system PinmemberCPallini23:03 1 Apr '07  
GeneralRe: The .resx registry fix doesn't work on my system PinmvpMichael Dunn20:14 2 Apr '07  
GeneralI think you should give more emphasis to.. PinmemberCPallini22:51 1 Apr '07  
GeneralAdvertising... Pinmemberstarschen4:57 4 Jan '07  
QuestionHow To Register a dll ? Pinmembermurtazadhari8:34 4 Oct '06  
AnswerRe: How To Register a dll ? PinsitebuilderMichael Dunn8:52 4 Oct '06  
GeneralExcellent Tool PinmemberBassam Abdul-Baki4:06 25 Mar '05  
GeneralRe: Excellent Tool PinsitebuilderMichael Dunn6:16 25 Mar '05  
GeneralRe: Excellent Tool PinmemberBassam Abdul-Baki6:50 25 Mar '05  
GeneralRe: Excellent Tool PinsitebuilderMichael Dunn7:07 25 Mar '05  
GeneralRe: Excellent Tool PinmemberBassam Abdul-Baki7:25 25 Mar '05  
GeneralRe: Excellent Tool PinmemberBassam Abdul-Baki7:31 25 Mar '05  
GeneralAn suggestion: Don NOT use Win95TruncatedExtensions technique PinmemberBehzad Ebrahimi4:15 25 Nov '04  
GeneralAccessing Medias with ShFileOperation PinsussAnonymous3:06 17 Aug '03  
GeneralRe: Accessing Medias with ShFileOperation PinsitebuilderMichael Dunn7:38 17 Aug '03  
GeneralCompile - Error's PinmemberHTempelman2:43 4 Jul '03  
GeneralRe: Compile - Error's PinsitebuilderMichael Dunn4:52 4 Jul '03  
GeneralRe: Compile - Error's PinmemberHTempelman4:58 4 Jul '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 25 Dec 2002
Article Copyright 2000 by Michael Dunn
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid