I have created a program that generates an application which I have saved in a certain location, lets use C:\Documents and Settings\UserName\Desktop\Folder\ as an example. The program uses this base location, then searches through some subfolders, alters a file, and saves the altered file in the base location that the application is running from. Right now, I have the Base Location statically defined in my C++ code. Is there any way of making my program read the location the app is running from without actually defining it, because the program needs to run on different computers (The end product will be located on a shared "J:" drive instead of "C:"). I am using Microsoft Visual C++ 6.0 (I know its old!).

Recommended Answers

All 5 Replies

Are you using an installer or just copying the files manually to each new machine?

This Q&Awill help you (first one at the top of the page)

Are you using an installer or just copying the files manually to each new machine?

I'm just manually writing them to a new location (the Base Location). I'm using outputfile.open(filename) where "filename" is just the path to the location the app is running from. I have that location defined at the very top of my code:

#define BASE_DIRECTORY "C:\\Documents and Settings\\username\\Desktop\\Folder\\"

string filename = BASE_DIRECTORY;
filename.append("Actual Name of the file found in subfolder");

My program does exactly what I want it to right now the way it is, with the exception of defining BASE_DIRECTORY. I don't want to define base directory so that it will work on any computer it's saved to.
Is there anyway to get it to search for its own location and assign it to a string called Base_Directory? That would be perfect.

Does that help?
Thanks in advance

Shall I repeat myself -- use GetModuleFileName() -- this will return the full path where the program that is currently running was started. If you are trying to get the path of another program then this will not help you.

Shall I repeat myself -- use GetModuleFileName() -- this will return the full path where the program that is currently running was started. If you are trying to get the path of another program then this will not help you.

Thank you, that was exactly what I needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.