Solved

Deleting files

Posted on 2002-05-02
8
203 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now