For inthe - 10205304

I had found a question on deleting temp internet files and promised to award points for the question separately from the other person that had posted the question. I hadn't realized that so much time had gone by, my apologies to inthe.

The answer from inthe ...

like so:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Registry;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
function FindTemporaryFiles : String;
var
  TheReg : TRegistry;
  TempString : String;
begin
  TheReg := TRegistry.Create;
  try
    TheReg.RootKey := HKEY_CURRENT_USER;
    If TheReg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\', False ) then
      begin
        TempString := TheReg.ReadString('Cache');
        If Copy(TempString, Length(TempString) - 1, 1) <> '\' then
          TempString := TempString + '\';
        Result := TempString;
      end
    else
      Result := 'NOTHING';
  finally
    TheReg.Free;
  end;
end;

procedure GatherFiles(Const Lines: TStrings; Const Dir,Match: String);
var
  Rec: TSearchRec;
  Found: Integer;
Begin
  // Add files
  Found:= FindFirst(Dir+'\'+Match, faAnyFile, Rec);
  While Found = 0 do
    begin
      If (Rec.Attr AND faDirectory) = 0 Then Lines.Add(Dir+'\'+Rec.Name);
        Found := FindNext(Rec);
    End;
  FindClose(Rec);
  // Find directories (Without match)
  Found:= FindFirst(Dir+'\*.*', faAnyFile, Rec);
  While Found = 0 do
    begin
      If ((Rec.Attr AND faDirectory)>0) AND (Rec.Name<>'.') AND (Rec.Name<>'..') Then
        GatherFiles(Lines,Dir+'\'+Rec.Name,Match);
      Found := FindNext(Rec);
    End;
  FindClose(Rec);
End;

procedure TForm1.Button1Click(Sender: TObject);
Var
  TempPath : String;
  TheList : TStringList;
  i : integer;
begin
  TheList := TStringList.Create;
  try
    TempPath := FindTemporaryFiles;
    If (length(TempPath) > 3) AND (UPPERCASE(TempPath) <> 'C:\WINDOWS') AND (UPPERCASE(TempPath) <> 'C:\WINNT') then
      begin
        GatherFiles(TheList,TempPath,'*.*');
        For i := 0 to TheList.Count - 1 do
            try
              DeleteFile( TheList[i] );
            except
           end;
      End;
    finally
      TheList.Free;
    end;
    showmessage('finished');
 end;


end.

Regards Barry
LVL 6
reddarinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
Hi Reddarin,

note for nt this would be changed to:

If TheReg.OpenKey('Software\Microsoft\Internet Explorer\Main\', False ) then
begin
TempString := TheReg.ReadString('Cache_Directory');

but we now know a more proper way thanks to
http://www.euromind.com/iedelphi/IECache.htm

the site above is great and has many useful ie stuff.
have a good one :-)
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
reddarinAuthor Commented:
Adjusted points to 200
0
reddarinAuthor Commented:
Thanks again Barry =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.