[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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
0
reddarin
Asked:
reddarin
  • 2
1 Solution
 
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
 
reddarinAuthor Commented:
Adjusted points to 200
0
 
reddarinAuthor Commented:
Thanks again Barry =)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now