Search code examples
windowsc++11launcherworking-directory

How to Change Working Directory C++11


I'm fairly new to C++ and I want to make a Program Launcher, All it does is launch applications for me based on text I input.

I all ready have the basic code for it, but I can't seem to find out how to change the working directory. I know you use chdir, but how Exactly.


Solution

  • C++ still has very little standardized support for filesystem functions, in part because it runs on embedded devices which may not have working directories, or sometimes even directories or files at all. So we have to look to the OS API.

    For POSIX, there is chdir() and getcwd().

    For Windows, there is SetCurrentDirectory and GetCurrentDirectory, although if you want to deal with per-drive working directory, you will need to work with environment variables.

    There is an example on MSDN titled Changing the Current Directory