Solved

Deleting files

Posted on 2002-05-02
8
202 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
Comment Utility
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
Comment Utility
whats the code ?
0
 

Author Comment

by:tyfing
Comment Utility
from the whole PC
0
 
LVL 8

Expert Comment

by:Cesario
Comment Utility
Dear tyfing,

this is what you need

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

Best Regards

Cesario
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Expert Comment

by:Cesario
Comment Utility
you can call the procedure with:

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

Author Comment

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

Expert Comment

by:Cesario
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

11 Experts available now in Live!

Get 1:1 Help Now