Solved

Check if file Exist only

Posted on 2001-08-20
7
212 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
[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
  • 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
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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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