[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Deleting files

Posted on 2002-05-02
8
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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