We're using Visual Studio 2005 (2.0 of the framework) and while I have
considerable experience with VB and C#, I have not so much with VC++. I've
run into something that's puzzling me, and can't find anything addressing it
online (not using the proper search terms, I expect)..

I'm working on an existing application which I've retrtieved from a
repository. One of the pre-existing unit tests is failing, it's trying to
locate a particular file using a relative path (up four levels and then down
another directory branch). I added some code to see what exactly the current
directory is, and it's one level higher than I expected. I was thinking it
would be in the "Debug" folder (running in debug mode) inside the
application's folder, which is where it normally is for C# and VB. But the
current directory is one level above the Debug folder.

If the current directory was the Debug folder, then the relative path would
lead to the file it's looking for. These unit tests work for other
developers, so it's obvious their current directories are one level lower
than mine, in the "Debug" or "Release" folders.

I've tried looking for some setting but don't see one out of the ordinary.
Project Properties shows the output directory to be
$(SolutionDir)$(ConfigurationName).

What am I missing?

Any help will be greatly appreciated.

Re: Current Directory? by David

David
Fri Jan 04 08:57:42 CST 2008

CapCity wrote:
> We're using Visual Studio 2005 (2.0 of the framework) and while I have
> considerable experience with VB and C#, I have not so much with VC++. I've
> run into something that's puzzling me, and can't find anything addressing it
> online (not using the proper search terms, I expect)..
>
> I'm working on an existing application which I've retrtieved from a
> repository. One of the pre-existing unit tests is failing, it's trying to
> locate a particular file using a relative path (up four levels and then down
> another directory branch). I added some code to see what exactly the current
> directory is, and it's one level higher than I expected. I was thinking it
> would be in the "Debug" folder (running in debug mode) inside the
> application's folder, which is where it normally is for C# and VB. But the
> current directory is one level above the Debug folder.
>
> If the current directory was the Debug folder, then the relative path would
> lead to the file it's looking for. These unit tests work for other
> developers, so it's obvious their current directories are one level lower
> than mine, in the "Debug" or "Release" folders.
>
> I've tried looking for some setting but don't see one out of the ordinary.
> Project Properties shows the output directory to be
> $(SolutionDir)$(ConfigurationName).

CapCity:

An application should not assume anything about the current working
directory.

When you run a VC application from the IDE, the working directory is the
project directory (the one with the .vcproj file). When you run any
application by double-clicking from Windows Explorer, the working
directory is the one where the executable is located. If you start an
application from a shortcut, the working directory is specified in the
shortcut. If you start it from the command line, the working directory
is that of the command line environment.

In short, it could be anywhere.

In my (native) VC application, I always use ::GetModuleFileName() to get
the executable directory, and work from there.

--
David Wilkinson
Visual C++ MVP

Re: Current Directory? by Klueless

Klueless
Fri Jan 04 12:22:35 CST 2008

"CapCity" <sgomori at yahoo dot com> wrote in message news:uWJ7F%23tTIHA.5160@TK2MSFTNGP05.phx.gbl...
> If the current directory was the Debug folder, then the relative path would lead to the file it's looking for. These unit tests
> work for other developers, so it's obvious their current directories are one level lower than mine, in the "Debug" or "Release"
> folders.

Use project settings to set the Configuration Properties, Debugging, "Working Directory".