Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

delete file

Posted on 2001-09-02
10
Medium Priority
?
182 Views
Last Modified: 2010-04-06
I keep deleting one and the same file all over again.How can i programm it so the app. does it for me and after done it terminates automatucally.
Example is :
I keep deleting file:D:\Example\rubbish.dat
How am I tto make an simple app. so it does it for me.???
0
Comment
Question by:Bosanac
[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
  • 6
  • 2
  • 2
10 Comments
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6449720
DeleteFile('D:\Example\rubbish.dat');
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6449722
From Delphi help

Deletes a file from disk.

Unit

Sysutils

Category

file management routines

function DeleteFile(const FileName: string): Boolean;

Description

DeleteFile erases the file named by FileName from the disk. If the file cannot be deleted or does not exist, the function returns False.


The Crazy One
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6449732
I put toghether an app that I run when the OS startups up to delete cookies and .tmp and various other files that I don't want hanging around on my system. Perhaps you might want do that as well. The DeleteFile function is real easy to use but make sure of what you are deleting when using it because the function does not use the Recycle Bin.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Dennis9
ID: 6450724
Hi.
Just do this in the forms oncreate event:

///Example
procedure TForm1.FormCreate(Sender: TObject);
begin
DeleteFile('D:\Example\rubbish.dat');
Application.ProcessMessages;
Application.Terminate;
end;


Dennis
0
 

Author Comment

by:Bosanac
ID: 6450732
Is this OK??

if FileExists('D:\Private') then begin
 DeleteFile('D:\Private');
  Application.terminate;
 end
 else  begin showmessage ('File does not exist !');
 application.processmessages;
 application.terminate;

 end;
end;
0
 
LVL 1

Expert Comment

by:Dennis9
ID: 6450749
This will work, u need to have the extension with it.

Var
str:string;

Begin
str:= 'D:\Example\rubbish.dat';

if FileExists(str) then
begin
DeleteFile(str);
application.processmessages;
Application.terminate;
end
else  
begin
showmessage ('File '+str+' does not exist!');
application.processmessages;
application.terminate;
end;

Dennis
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6450927
Hi Bosanac
Yes your code should work as long as Private is a file and not a folder. Personally this is the way I would do it.

var
     sFileToDel, sMsg: string;

begin
     sFileToDel := 'D:\Private';
     if not DeleteFile(sFileToDel) then begin

          if not FileExists(sFileToDel) then
               sMsg := 'File not found'
          else
               sMsg := 'Could not delete file';

          ShowMessage(sMsg);
     end;

end;    
0
 

Author Comment

by:Bosanac
ID: 6450980
Why is it that my form pops up during runtime (deleting or whatever...)though I declared form1.visible:=false????
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6451162
Well this is the way I do it.

procedure TForm1.FormCreate(Sender: TObject);
begin
     Form1.Visible := False;
     try
          DoYourCode;
     finally
          Form1.Free;
     end;
end;
0
 
LVL 44

Accepted Solution

by:
CrazyOne earned 200 total points
ID: 6451177
If the form is not the main form you could do it like this.

procedure TForm1.FormCreate(Sender: TObject);
begin
     Form1.Visible := False;
     try
          DoYourCode;
     finally
          Form1.Free;
              if not Application.Terminated then
               Application.Terminate;
     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

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…
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 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