Solved

Check if file Exist only

Posted on 2001-08-20
7
211 Views
Last Modified: 2010-04-06
Hello when i start my application the first thing i want it to do automatically is check to see if a file exist in a dir.

the file is called   Check.dat its in C:\

now if Check.dat exist then do nothing

but if Check.dat is not exist then the Appliacation Exits

thanks in advance  give to me full example because i am new and learning thank you
0
Comment
Question by:neopolis
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 6408795
Im not sure this is what you want, but this should do it :

if FileExists('c:\Check.dat') then do something...

Regards
Peter
0
 

Author Comment

by:neopolis
ID: 6409455
Hi Peter

what i want is some code

that checks for the Check.dat file in windows dir
if the file is there then the application stay running

if the file is not there then the application Exits

thanks
0
 
LVL 3

Accepted Solution

by:
VSF earned 10 total points
ID: 6409469
Open your .dpr by going on Menu>Project>ViewSource

Add SysUtils to uses clause
and before the "Application.run;" add the if statement!
The final code of your .dpr should look like this:

program Project1;

uses
  Forms,Sysutils,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  if fileexists('ADD HERE THE PATH OF THE FILE') then
   Application.Run
  else                 //Terminates the program if notfound
   application.terminate;
end.



Hope this helps!
VSF
www.victory.hpg.com.br

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 2

Expert Comment

by:PeterLarsen
ID: 6409504
Yo VSF,

I think what Neopolis want is to search throught the windows directory.
To do that you must open the registry first to find the path :-(

/Peter :-)
0
 

Author Comment

by:neopolis
ID: 6409852
Thank you Peter
0
 
LVL 3

Expert Comment

by:VSF
ID: 6410758
PeterLarsen:
Noops... I think that was what he needed!

Neopolis:
I'm glad to help!

Post your questions if you have any problems... We'll allways be here to try to solve then!

VSF
UIN:14016999

Please show your support by entering my sites!
www.victory.hpg.com.br
www.enge.cjb.net
0
 

Author Comment

by:neopolis
ID: 6412547
i went to your site cool i bookmarked so i will be back
*smiles*
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 81
Delphi...Split view - idea? 1 90
Tvertscrollbox like a whatsapp layout 5 36
DBCtrlGrid, Delphi, Scroll 7 26
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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