I have an application that is connected to some external sources (text and image files). I refer to these sources through their full path. The sources are located in the same folder as the application (the executable).
Whenever I move the folder which contains the application and the sources to another directory, the sources are (for natural reasons) unreachable if I don't change the path in the source code.
I would like to know if there is a way to point directly to the containing folder of the application and the sources so I (or someone else) can run the application correctly from whatever directory without having to change the path in the source code or moving the folder to a specific directory.
Any suggestions are appreciated.
Refering to external files without using full path
Started by Zeddan, Oct 20 2008 10:01 AM
5 replies to this topic
#1
Posted 20 October 2008 - 10:01 AM
|
|
|
#2
Posted 22 October 2008 - 06:57 PM
I believe there is a function called "GetModuleFileName" or something like that. (I don't use it much and I don't have a reference in front of me.... so someone else might clarify). It will return the path of where your exe is. Then do a reverse search on that path until you reach a "\" character. Chop off the rest and add on the relative file names:
Ie:
Something like that should probably get what you want...
Ie:
CString GetMyFilePath(CString relative)
{
CString path;
GetModuleFileName(path.GetBuffer(256);
int pos = path.ReverseFind('\\');
return path.Left(pos+1) + relative;
}
Something like that should probably get what you want...
Edited by Jaan, 23 October 2008 - 08:39 PM.
Please use code tags when you're posting your codes!
#3
Posted 25 October 2008 - 04:01 AM
you could also do
string path; path = Application.StartupPath + "\\";It will set it as the executables path, without the executable's filename in it and then add a \ onto it.
Edited by Termana, 25 October 2008 - 04:05 AM.
Added Code into [CODE][/CODE]
#4
Posted 25 October 2008 - 10:05 PM
I would like to know if there is a way to point directly to the containing folder of the application and the sources so I (or someone else) can run the application correctly from whatever directory without having to change the path in the source code or moving the folder to a specific directory.
#5
Posted 27 October 2008 - 06:05 PM
If I understand what you've just said rashed2007 - aren't you just asking the same question that the opening poster asked? (that has been answered btw)
Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!
#6
Posted 28 October 2008 - 05:58 AM
Termana said:
you could also do
string path; path = Application.StartupPath + "\\";It will set it as the executables path, without the executable's filename in it and then add a \ onto it.
Lol just put it all on one line!
string path = Application.StartupPath + "\\";


Sign In
Create Account


Back to top









