File System directory issues
File System directory issues
I am working on my game from different computers occasionally. How can I change my working directory to something relative to my project folder, not the whole computer?
For example, in Computer A my working directory is:
"C:\ComputerAFiles\MyProject\"
In Computer B, my working directory is:
"D:\BFiles\Stuff\MyProject\"
How can I detect and set my directory to the relative path of "\MyProject\"? Do I have to manually parse the getWorkingDirectory string to find out the last folder?
Remember that the starting directory isn't always the same: if I open one of my scenes (custom file format), open the .exe directly, or run it from the VS2008 debugger, I get a different starting working directory.
Also, how exactly does getFileDir work? Do I just input the name of any file and it should find it and tell me its full path? That doesn't seem realistic. When I tried it, it just outputted garbage.
For example, in Computer A my working directory is:
"C:\ComputerAFiles\MyProject\"
In Computer B, my working directory is:
"D:\BFiles\Stuff\MyProject\"
How can I detect and set my directory to the relative path of "\MyProject\"? Do I have to manually parse the getWorkingDirectory string to find out the last folder?
Remember that the starting directory isn't always the same: if I open one of my scenes (custom file format), open the .exe directly, or run it from the VS2008 debugger, I get a different starting working directory.
Also, how exactly does getFileDir work? Do I just input the name of any file and it should find it and tell me its full path? That doesn't seem realistic. When I tried it, it just outputted garbage.
well by default irrlicht searches in the same folder the .exe was launched from... if you for example place all your models textures and sounds in:
bla/bla/myProject/media
and your .exe is in:
bla/bla/myProject/bin or
bla/bla/myProject/release or
bla/bla/myProject/debug
to get to your files you would use a RELATIVE path to access them like so:
scene::IAnimatedMesh* myMesh = smgr->getMesh("../media/myMesh.x");
where the two dots and the slash (../) is what your looking for... hopefully...
bla/bla/myProject/media
and your .exe is in:
bla/bla/myProject/bin or
bla/bla/myProject/release or
bla/bla/myProject/debug
to get to your files you would use a RELATIVE path to access them like so:
scene::IAnimatedMesh* myMesh = smgr->getMesh("../media/myMesh.x");
where the two dots and the slash (../) is what your looking for... hopefully...
Actually, the only time the working directory is equal to the folder of the .exe file is when I open the .exe file directly (through Windows Explorer).
I'm making a map editor, and when I try to directly open a map file (through Windows Explorer) with my program, the working directory becomes the directory of the map file, not my program's .exe file's directory. Likewise, when I run the VS2008 debugger, the working directory becomes my .vcproj file's directory, not my .exe file's directory.
Is there a way to consistently find the same relative directory?
I'm making a map editor, and when I try to directly open a map file (through Windows Explorer) with my program, the working directory becomes the directory of the map file, not my program's .exe file's directory. Likewise, when I run the VS2008 debugger, the working directory becomes my .vcproj file's directory, not my .exe file's directory.
Is there a way to consistently find the same relative directory?
VS starts the .exe from your $(SolutionDir) which is set to the .vproj dir and saves the exe in the $(SolutionDir)$(ConfigurationName). You can change this in the projects settings, if you want to.
If you open a file using the OpenFileDialog, the working dir is changed by Irrlicht (a bit dirty), so maybe you have to set it to the old dir.
If you open a file using the OpenFileDialog, the working dir is changed by Irrlicht (a bit dirty), so maybe you have to set it to the old dir.
the problem he is having is this:
he has assosiated a map/mesh or what ever extension with his program...
let's say the program is "C:\programs\myProg\theProg.exe" and the map/mesh is "D:\map\data\theMap.3ds"...
now, if he double klicks the map/mesh then the program will start, but the working directory is the one from the map/mesh and not the one from the program !!!
EDIT: the solution could be to use the arguments passed to function main:Edit 2:
he has assosiated a map/mesh or what ever extension with his program...
let's say the program is "C:\programs\myProg\theProg.exe" and the map/mesh is "D:\map\data\theMap.3ds"...
now, if he double klicks the map/mesh then the program will start, but the working directory is the one from the map/mesh and not the one from the program !!!
EDIT: the solution could be to use the arguments passed to function main:
Code: Select all
int main(int argc, char** argv){
// argv[0] holds the name of the exe incl. path
printf("%s\n",argv[0]);
// argv[1] holds the name of the assosiated file incl. path
if(argc > 1) printf("%s\n",argv[0]);
system("pause");
return 0;
}Code: Select all
// and getFileDir() can be used to get the directory
stringc theDir = FileSystem->getFileDir(stringc(argv[0]));
Last edited by Acki on Sun Jan 18, 2009 8:08 pm, edited 2 times in total.
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Exactly!Acki wrote:the problem he is having is this:
he has assosiated a map/mesh or what ever extension with his program...
let's say the program is "C:\programs\myProg\theProg.exe" and the map/mesh is "D:\map\data\theMap.3ds"...
now, if he double klicks the map/mesh then the program will start, but the working directory is the one from the map/mesh and not the one from the program !!!
The only way I can get it to work consistently is if I just set the working directory to "C:\programs\etc", but using absolute paths like that is bad, since it'll fail if I change folder names or if I switch computers (which I do).
I am using a winforms gui, and if I find the directory with the .NET shell using this code:
Code: Select all
#undef GetCurrentDirectory
System::IO::Directory::GetCurrentDirectory();That's a good idea, I'll try that out.Acki wrote:EDIT: the solution could be to use the arguments passed to function main:Code: Select all
int main(int argc, char** argv){ // argv[0] holds the name of the exe incl. path printf("%s\n",argv[0]); // argv[1] holds the name of the assosiated file incl. path if(argc > 1) printf("%s\n",argv[0]); system("pause"); return 0; }
Hm it doesn't work. The args array is empty unless I open a file. If I open a file, the only argument is the path of the file that I am opening, not the .EXE.
I am using CLR, if that makes a difference:
I am using CLR, if that makes a difference:
Code: Select all
int main(cli::array<System::String ^> ^args)realy ??? 
hmm, do you realy need the function this way,
or can you not just simply change it to the other format ???
hmm, do you realy need the function this way,
or can you not just simply change it to the other format ???
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
unfortunately I never used .net, so I don't know about this...
but I can't imagine that this is the only valid style to use...
but I don't know, though it could be...
sorry, I can't help you further then...
but I can't imagine that this is the only valid style to use...
but I don't know, though it could be...
sorry, I can't help you further then...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
yes, not a bad idea, if all others fail !!!zillion42 wrote:get nsis (nullsoft scriptable install system) and write a small installer which sets a registry value with the path to the .exe, and retrieve that path with .net code from inside your application.
I think this is possible with all (good) setup tools (e.g. InnoSetup)...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Actually I just found out a pretty weird but simple way to do it:
"path" gives the full path of the exe file.
Thanks for the suggestions.
Code: Select all
char path[MAX_PATH + 1];
GetModuleFileNameA( NULL, path, MAX_PATH + 1 );
Thanks for the suggestions.