# Thread: Changing the active dir

1. ## Changing the active dir

How can I change the dir the program is using, in windows. (ie what is the windows equivelant of system("c:\\dir\\to\\change\\to). Also how can I figure out the folder that the program is in?

2. You can change the surrent directory with chdir(), and GetModuleFileName() will return the full path of the current module. Look them up in the help.

3. For wanting to know the program's current directory, you'll want to get the handle of the program:

HINSTANCE hInstance = GetModuleHandle(NULL);

Now you have the handle of the program. (This is kinda funny because the program is passing itself its own handle).

I don't know what you want to do with it but you could do something creative like print out the directory:

Code:
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);

GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
This will print out the directory that the program is running from.

Not sure how to change directories though... depends on what you want to do by changing directories, I guess.

4. Thanks guys

5. There is also

GetCurrentDirectory()

and

SetCurrentDirectory()

6. Whoa - cool, thanks novocain!

Newbie myself, don't know all the functions there are....