Solved

Deleting files

Posted on 2002-05-02
8
205 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 157
delphi parse string to params 3 137
control image tags in a string ? 12 142
Graphics32 under Delphi 10.1 Berlin 2 105
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

821 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