get "Program Files" directory

This is a discussion on get "Program Files" directory within the Windows Programming forums, part of the Platform Specific Boards category; Hey everyone, I'm trying to write a function that finds the default Program Files directory. I've created one that write ...

  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
    1,605
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

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, 01: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, 08:43 AM
  5. The Site Directory
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-22-2002, 07:19 PM

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