Changing the active dir

This is a discussion on Changing the active dir within the Windows Programming forums, part of the Platform Specific Boards category; 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). ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    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. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    50
    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. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Thanks guys

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    There is also

    GetCurrentDirectory()

    and

    SetCurrentDirectory()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    50
    Whoa - cool, thanks novocain!

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-25-2007, 03:48 PM
  2. Changing windows without changing?
    By Lionmane in forum Windows Programming
    Replies: 7
    Last Post: 10-19-2005, 12:41 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. changing "active" dir
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 04-23-2002, 11:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21