« Xbox 360 Controller Wireless Receiver Ad... | Main | Adding a Timeline to DasBlog with the SI... »

Clean up your Temp Files

Posted 2007-02-16 11:06 AM in ASP.NET | Tools.

I was doing some tidying up on a website for a family friend recently. His ASP.NET application was taking longer and longer to start up. It also happened to use a lot of XmlSerializers, and of course, as an ASP.NET app, there's a lot of page-by-page compilation as he's not on 2.0 and doesn't use aspnet_compiler.

Additionally, there's some code that this client wrote that writes out temp files but doesn't clean up after themselves. When there's this many files in a folder, calls to GetTempFileName can block for many seconds.

Not only can "excessive temp file growth" cause pain at runtime, but it'll easily crush Explorer.exe's usefulness. It'll also become impossible to apply Attributes to the folder.

The point is, that there's a few folders that you need to watch out for file growth in.

I like to modify the options inside Microsoft Drive Cleanup using Shawn A. Van Ness's registry file. You can extensively modify what appears in the Drive Cleanup list, even adding your own file types and your own application-specific directories and files that you might want cleaned up.

Check out your own systems...drop out to a command prompt (cmd.exe) and do:

  • cd %tmp% and cd %temp% - You'll usually end up in C:\DOCUME~1\username\LOCALS~1\Temp.
    • At this point, I like to do the equivalent of a deltree and go up a directory and:
      • cd ..
      • rd Temp /s (it usually won't manage to delete the whole dir. Someone will have a file open and the final directory deletion will fail)
      • md Temp (in case it was deleted.)
  • Everything in %windir%\temp - There's lots of Perfmon counters in here, so you won't be able to delete everything. Often you can del *.* and anything that shouldn't be deleted is currently open.
  • If you are a developer, and have developed ASP.NET for years/months, clean up %windir%\Microsoft.NET\Framework\ <VERSION> \Temporary ASP.NET Files. I had 4 dozens sites in here.

Tidy up, my friends.

Tracked by:
"Clean up your Temp Files" (help.net) [Trackback]


Friday, February 16, 2007 11:54:41 AM (Pacific Standard Time, UTC-08:00)
I just run this perl script that cleans up my temp dirs --- and it's lightning quick!

<code>
use File::Find;

my $UserTemp;
$UserTemp = $ENV{Temp};
$WinTemp = $ENV{windir};
$WinTemp="$WinTemp\\Temp";

find(\&Wanted, $UserTemp);
&smash("$UserTemp");

find(\&Wanted, $WinTemp);
&smash("$WinTemp");

print "\n\tSUCCESS: \"$UserTemp\" has been cleared!";
print "\n\tSUCCESS: \"$WinTemp\" has been cleared!\n";

sub Wanted {
#print $File::Find::topdir."\n";
opendir(DIR,$File::Find::topdir) or return;
my $current = $_;
my @List=readdir(DIR);
closedir(DIR);
splice(@List,0,2);

if (-f $current) {
unlink $File::Find::name;
}
}

sub smash {
my $dir = shift;
opendir DIR, $dir or return;
my @contents =
map "$dir/$_",
sort grep !/^\.\.?$/,
readdir DIR;
closedir DIR;
foreach (@contents) {
next unless !-l && -d;
&smash($_);
rmdir $_;
}
}
</code>
I'm an Anonymous Coward
Friday, February 16, 2007 12:11:09 PM (Pacific Standard Time, UTC-08:00)

That's nothing! Find someone who hasn't run spyware on their computer. Holy bejeezuss. Figure 100+ if this person browses at all.
John A. Davis
Friday, February 16, 2007 2:41:22 PM (Pacific Standard Time, UTC-08:00)
The other benefit of that Perl script I posted is that it doesn't get hung up on files that it can't delete (ususally b/c a process has some temp file locked). It just moves along to the next one.
I'm an Anonymous Coward
Friday, February 16, 2007 3:38:32 PM (Pacific Standard Time, UTC-08:00)
Crap Cleaner (ccleaner)is the only way to fly for all kinds of sqeaky clean goodness. isnt it already on your tools list? if not, why not? :)
Some Kind of anonymoose
Friday, February 16, 2007 3:38:50 PM (Pacific Standard Time, UTC-08:00)
Crap Cleaner (ccleaner)is the only way to fly for all kinds of sqeaky clean goodness. isnt it already on your tools list? if not, why not? :)
Some Kind of anonymoose
Monday, February 19, 2007 9:38:29 AM (Pacific Standard Time, UTC-08:00)
REM ClearTemp.cmd

@echo off
del "%TEMP%\*.*" /s /f /q
for /d %%d in (%TEMP%\*) do rmdir "%%d" /s /q

del "%WINDIR%\TEMP\*.*" /s /f /q
for /d %%d in (%WINDIR%\TEMP\*) do rmdir "%%d" /s /q
pause
DuncanS
Comments are closed.

Contact

Sponsors

Hosting By

Hot Topics

Tags

Calendar

<November 2009>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Archives

November, 2009 (2)
October, 2009 (19)
September, 2009 (11)
August, 2009 (12)
July, 2009 (21)
June, 2009 (26)
May, 2009 (16)
April, 2009 (13)
March, 2009 (17)
February, 2009 (17)
January, 2009 (18)
December, 2008 (32)
November, 2008 (17)
October, 2008 (22)
September, 2008 (16)
August, 2008 (14)
July, 2008 (25)
June, 2008 (19)
May, 2008 (17)
April, 2008 (17)
March, 2008 (26)
February, 2008 (21)
January, 2008 (28)
December, 2007 (19)
November, 2007 (17)
October, 2007 (31)
September, 2007 (39)
August, 2007 (37)
July, 2007 (43)
June, 2007 (37)
May, 2007 (32)
April, 2007 (38)
March, 2007 (29)
February, 2007 (46)
January, 2007 (31)
December, 2006 (27)
November, 2006 (31)
October, 2006 (32)
September, 2006 (39)
August, 2006 (34)
July, 2006 (40)
June, 2006 (18)
May, 2006 (31)
April, 2006 (34)
March, 2006 (30)
February, 2006 (38)
January, 2006 (44)
December, 2005 (19)
November, 2005 (34)
October, 2005 (24)
September, 2005 (37)
August, 2005 (20)
July, 2005 (24)
June, 2005 (33)
May, 2005 (16)
April, 2005 (22)
March, 2005 (34)
February, 2005 (15)
January, 2005 (37)
December, 2004 (28)
November, 2004 (30)
October, 2004 (34)
September, 2004 (22)
August, 2004 (34)
July, 2004 (18)
June, 2004 (64)
May, 2004 (49)
April, 2004 (21)
March, 2004 (29)
February, 2004 (29)
January, 2004 (36)
December, 2003 (25)
November, 2003 (24)
October, 2003 (59)
September, 2003 (42)
August, 2003 (24)
July, 2003 (44)
June, 2003 (29)
May, 2003 (21)
April, 2003 (30)
March, 2003 (27)
February, 2003 (47)
January, 2003 (50)
December, 2002 (31)
November, 2002 (38)
October, 2002 (44)
September, 2002 (15)
May, 2002 (2)
April, 2002 (4)

Google Ads