Thread: get "Program Files" directory

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    get "Program Files" directory

    Hey everyone,

    I'm trying to write a function that finds the default Program Files directory. I've created one that write the directory to a file, then it gets opened for reading, but this is extremely unproductive and I was wondering if there is a way around this:

    Code:
    string PgmFilesDir()
    {
        system("echo %PROGRAMFILES%>pgmfiles.txt");
        
        ifstream f ("pgmfiles.txt");
        
        if ( !f.is_open() )
        {
            cout << "ERROR! Unable to locate program files directory!" << endl << "Press a key to quit.";
            system("pause>nul");
            ExitProcess(0);
        }
        
        string pgmfiles;
    
        getline(f, pgmfiles, '\n');
        
        return pgmfiles;
    }
    I'm trying to avoid the use of the system() command...

    Any help will be greatly appreciated.

    Thanks,

    Matt
    ~guitarist809~

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  3. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  4. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 09:43 AM
  5. The Site Directory
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-22-2002, 08:19 PM