I want to set the current directory to the solution directory/configuration name. How do I do that? Can I use the global variables somehow?
I am trying to read a file and the current directory changes in the middle of the code. I want to change it back.
Answer: Use the cd Command The current working directory is the directory or folder where you are currently working. You can use the cd (change directory) command to change the current working directory or move around the file system. This command will work in all Linux distribution.
In Visual Studio 2010: Go to the project properties (rigth click on the project name in the Solution Explorer, then Properties on the pop up menu). Then, under Configuration Properties / Debugging, set Working Directory to $(SolutionDir)$(Configuration)\ .
$(ProjectDir)The directory of the project (defined as drive + path); includes the trailing backslash '\'.
In Visual Studio 2010:
$(SolutionDir)$(Configuration)\
.Full list of available macros (on docs.microsoft.com) : Common macros for MSBuild commands and properties
You can use the posix subsystem ( <direct.h>
) and access the functions
_getcwd()/_wgetcwd()
Gets the current working directory_chdir()/_wchdir()
Sets the current working directory
If you need your code to be cross platform, you can do the following:
#ifdef _WIN32
# include <direct.h>
# define getcwd _getcwd
# define chdir _chrdir
#else
# include <unistd.h>
#endif
and use getcwd
and chdir
(w/o the leading underscore).
Have you tried using the environment variable $(SolutionDir)
?
With reference to this thread here.
Also, hopefully, the version of VS does not matter, but this answer is furnished based on the assumption that the platform is VS2005.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With