Solved

Check if file Exist only

Posted on 2001-08-20
7
208 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
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 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

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

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

22 Experts available now in Live!

Get 1:1 Help Now