Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a File

Status
Not open for further replies.

RobPouwelse

Technical User
Nov 19, 2001
77
NL
I have a made a program which uses a config file for certain variables (just a normal textfile with .cfg :))
Then problem is that i can only specify the location of the .cfg in my program.. i cannot genarate it, i could do it if i knew how to search my ENTIRE pc for that file. but the FindFirst function only searches the given directory (no subdir's)

the next best thing i could do is check if the file exists and if not then tell the user that it needs that file and he has to search for it himself :).. but that's userunfriendly.

tnx in advance... E-mail: Rob@matas.nl (till Jan 10, from then on it's Deathwish@winning.com)
 
It would be logical to put the config file together with the application.

Then U can use:

FileName:= ExtractFilePath(Application.ExeName) + 'MyConfig.cfg'

Another way is to let windows open the file, but then the config file must be linked to your application:

ShellExecute(Handle,'open',PChar('MyConfig.cfg'), nil, nil,SW_SHOW);
although I didn't tested it

Regards S. van Els
SAvanEls@cq-link.sr
 
Hi Rob,

What you could also do is when the file is first generated,
write the location of the file to the registry. Then you can
easily rettrieve it whenever you need it, since it will always be in the same location in the registry.

Although the way suggested by SvanEls is (in my opinion) the
best way to do it. Because that is the same way I use ini
files in my programs.

I hope this helps,

BobbaFet Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
 
Alternativly don't use a .cfg file at all and write the configuation data to the registry.

Unless you need the user to be able to select from one of many configurations this is the prefered way to do it.

Some of my apps use 'project' files. I write the location of the current file to the registry. This is the way that Bobbafet suggested.

Steve.
 
Use the registry if at all possible,
next use .ini files. Creating an ini file, windows I believe will create it in the local directory anyway. You could put it into the \Windows or windows\system directory as Windows searches local, windows and windows\system directories for the ini file automatically. The TRegistry class makes it a breeze to use and retrieve your settings. Last choice imho but sometimes necessary is to use a custom config file in the same directory as your app which as prev mentioned you get with ExtractFilePath(application.EXEName)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top