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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locating the folder which contains the program being executed.

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB

I have created an .exe file, myapp.exe, and it has been installed into the user’s designated folder, which might well be C:\Program files\ANM\myApplication.

The user has his application data in folder (say) c:\users\john, and there is a shortcut on the desktop which starts myapp.exe (from the program files folder) and runs it in the users\john folder

There are however other interesting files in the . . . ANM\myApplication folder, and I want to be able to refer to these files, both reading from and writing to them, under suitable program control.

How can I refer to this folder within myapp? I have tried to check this out by putting some Messagebox() instructions into the startup code of myapp, and observe these values.

CURDIR()…………\users\john
HOME()……………C:\PROGRAM FILES\COMMON FILES\MICROSOFT SHARED \VFPDEFAULT()………C:

Thanks. Andrew
 
I want to be able to refer to these files, both reading from and writing to them

It's not a good idea to try to write to files anywhere under [tt]\Program Files[/tt]. By all means use your executable folder for read-only files, such as a Help file or a config file. But for files that you will update in the application, use your main data directory, or the user's personal directly (My Documents or similar), or the user's Appplication Data directory.

There are two reasons for this: (i) Program Files, and all its sub-directories, are liable to raise UAC issues; and (ii) You need to consider whether multiple users will be updating the same files, and that will in part determine where to locate those files.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, I take the point about User account control.

What I want to achieve is to allow the user (or myself acting for him) to modify his own report layouts, particularly invoices and purchase orders. So, taking up your suggestion, when I am installing the application, I learn that the user has decided to use \users\john as his data folder. I then create a subfolder REPORTS into which I would place the standard reports, and it is up to him. Just a question of making sure that I know how to achieve that using the default Installshield.

It would mean that if there are several sets of data using the application, in different folders, each one would need to make its own changes, since it would have its own .frx/.frt files. But they might well find this convenient, if there were that level of customisation.

Andrew
 
In that case, I would use a sub-directory of the user's "personal" folder, that it, My Documents or Users\Documents (depending on the version of Windows). That way, each user can maintain their own copies of the relevant files, without stepping on other users' toes.

To locate the user's personal folder, use the code shown here: Finding the paths to Windows' special folders in VFP.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top