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!).

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

Edited 6 Years Ago by sodak: n/a

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.

Edited 6 Years Ago by Ancient Dragon: n/a

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.

This question has already been answered. Start a new discussion instead.