How to change working directory in Visual Studio

When developing a C++ program using Visual Studio, you typically compile and run it from the Visual Studio IDE. By default, when you do this, the executable is run with the working directory being the directory containing the Visual C++ project (.vcxproj). That is, this is the directory which acts as the current directory for your executable, when it run from within Visual Studio. Note that if you ran the executable from a commandline, then the working directory would be the current directory of your command prompt.

This behavior can be irritating if you have some files that your program needs to read or write. It would be nice if the executable considered the directory it resides in as the working directory. Changing this is easy:

  1. Open Project > Properties > Configuration Properties > Debugging.

  2. The Working Directory entry would be $(ProjectDir) by default. Change it to whatever you wish. If you want it to be the same directory as the place where the executable resides in, then change it to $(SolutionDir)$(Configuration)\

Tried with: Visual Studio 2012 and Windows 7 x64

5 thoughts on “How to change working directory in Visual Studio”

  1. “Note that if you ran the executable from a commandline, then the working directory would be the directory containing the executable file.”

    Not necessarily. If the executable is located at C:\foo\bar\run.exe and you are standing in C:\foo and start the program by doing: bar/run then the working directory will be C:\foo.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s