I am trying to run a C++ app (under Linux) from another directory. The app is supposed to read some files in the directory where it is. Let's assume the executable is in
/opt/app/proj/
All files to read by the app are in the same directory if I run the code from this directory, everything runs fine. but if I am in /home/user/Document/ and execute the code
/opt/app/proj/application
it does not find the files!! in my C++ code I have added something like:
string cwd(get_current_dir_name());
string path(argv[0]);
string CONFIG_FILE = "configuration.conf";
string FILETYPES = "extensions.txt";
int pos = path.find("./");
if(pos>=0){
path = cwd+path.substr(pos+1, path.length()-1);
}
pos = path.find_last_of("/");
path = path.substr(0,pos+1);
CONFIG_FILE = path + CONFIG_FILE;
FILETYPES = path + FILETYPES;
It still doesn't work.. Need help...