Solved

Deleting files

Posted on 2002-05-02
8
204 Views
Last Modified: 2012-05-04
how can i make my programme delete ALL emails (.eml) files when i click a button ?

i wanted to make a a virus cleaner as my company computers have alot of .eml files that contain nimda virus BUT we are using Lotus Notes as our emailing programme so deleting .eml files are safe.
0
Comment
Question by:tyfing
8 Comments
 
LVL 4

Expert Comment

by:nestorua
ID: 6986273
HI,
From all the computer or from the specific directory?
You can use f.e. FindFirst, FindNext and DeleteFile functions.
Sincerely,
Nestorua.
0
 

Author Comment

by:tyfing
ID: 6986296
whats the code ?
0
 

Author Comment

by:tyfing
ID: 6986297
from the whole PC
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 8

Expert Comment

by:Cesario
ID: 6986389
Dear tyfing,

this is what you need

http://www.preview.org/q/q1016.shtml

Best Regards

Cesario
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6986393
you can call the procedure with:

DeleteFiles ('c:\*.*', '*.eml', True);
0
 

Author Comment

by:tyfing
ID: 6986423
cesario, the code doesn't seem to work. i want the code all in a button.
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6986529
sorry, i have not test the code so now it should works fine

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

{**Summary ======================================================
    name    :   DeleteFiles
    PARAMS  :   const Path, Mask : string; recursive : boolean

    RETURNS :   -
    PURPOSE :   delete several files with joker.
                Optional recursive = search in subdirectories.

    EXAMPLE :   DeleteFiles ('c:\temp\', '*.txt', True);
    UPDATES :

    NOTES   :
    CODED   :   PT  15.10.96
  ===============================================================*}
procedure DeleteFiles (const Path, Mask : string; recursive : boolean);
var
  Result    : integer;
  SearchRec : TSearchRec;
begin

  Result := FindFirst(Path + Mask, faAnyFile, SearchRec);
  while Result = 0 do
  begin
    IF ((SearchRec.Attr AND faDirectory = 0) and (SearchRec.name <> '.') and (SearchRec.name <> '..')) then
    Begin
      if not DeleteFile (Path + SearchRec.name) then
      begin
        FileSetAttr (Path + SearchRec.name, 0); { reset all flags }
        DeleteFile (Path + SearchRec.name);
      end;
    End;
    Result := FindNext(SearchRec);
  end;
  FindClose(SearchRec);

  IF NOT recursive then exit;

  Result := FindFirst(Path + '*.*', faDirectory, SearchRec);
  while Result = 0 do
  begin
    if  (searchrec.attr  AND faDirectory = faDirectory) and
        (SearchRec.name <> '.') and (SearchRec.name <> '..') then
    begin
      DeleteFiles (Path + SearchRec.name + '\', Mask, TRUE);
    end;
    Result := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteFiles ('C:\', '*.eml', True);
end;

end.
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6988052
hi,
heres another this will search all drives for .eml and list them in combobox (or could be stringlist if you want to change it) then delete them.

unit Unit1;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure GatherFiles(Const Lines: TStrings; Const Dir,Match: String);
var
Rec: TSearchRec;
Found: Integer;
Begin
Found:= FindFirst(Dir+'\'+Match, faAnyFile, Rec);
While Found = 0 do
begin
Application.ProcessMessages;
If (Rec.Attr AND faDirectory) = 0 Then Lines.Add(Dir+'\'+Rec.Name);
Found := FindNext(Rec);
End;
FindClose(Rec);
Found:= FindFirst(Dir+'\*.*', faAnyFile, Rec);
While Found = 0 do
begin
Application.ProcessMessages;
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
b : byte;
drivenum : set of 0..25;
driveletter : string;
i : integer;
const
drivetype : array [0..6] of string = ('CD-Rom','Local Drive','Floppy Disk',
'Network Drive','RAM-Disk','Unknown','Unknown');
begin
integer(drivenum):=GetLogicalDrives;
for b := 0 to 25 do
if b in drivenum then
begin
driveLetter:=char(b + ord('A'));
GatherFiles(ComboBox1.Items,driveletter+':','*.EML');
end;
If ComboBox1.Items.Count>0 Then
ComboBox1.Text:= ComboBox1.Items[0];
ShowMessage('Found '+IntToStr(ComboBox1.Items.Count)+' matching files and now deleting them.');
for i := 0 to ComboBox1.Items.Count -1 do
 begin
  Showmessage('deleting ' + Combobox1.Items[i]);
  DeleteFile(Combobox1.Items[i]);
 end;
end;

end.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question