views:

932

answers:

2

What's happening to me is, when I run my program out of Visual studio, it can't use relative paths to find anything.

This is proving difficult to articulate...

Like, I've got program X, which opens textfile.txt, right? And if I point to textfile.txt with an absolute path, I'm fine. And if I point to it with a relative path and I compile program X, then run it directly (ie, by double-clicking programX.exe in the debug folder), I'm also fine. But, if I use a relative path and run the program out of visual studio (ie, by pressing f5), then it can't find the file.

Anyone know what's happening? Alternatively, can anyone suggest some decent keywords that don't collide squarely with other newbie Visual Studio issues?

Ben

+2  A: 

In VS 2008 in the properties of the exe project you can specify the run directory - the directory which the exe is run from.

Tom
+2  A: 

Not sure about VS2008 but earlier version ran the program with a current directory of debug (or release, I guess) underneath your project directory. You may have to make sure you use that as the root of your path.

Alternatively, prepend your relative path with "..\".

Temporarily put a system("cd"); inside your code to find out where it's actually running from or use GetCurrentDirectory(...) as suggested by Nick.

paxdiablo
This is correct in VS2008 also. You can also use GetCurrentDirectory() (iirc) to figure out where you are programmatically.
Nick
good call- wasn't running out of the debug directory like I expected. Thanks!
Ben