Programmatic access to current user's folder

Discussion in 'Mac Programming' started by Kurukuru, Apr 15, 2009.

  1. Guest

    #1
    Is it possible to open a file in the current user's home folder by doing something like (in C++):
    ifstream fIn("/~/somefile.ext", ios::binary);

    I know the code above does not work, but I wonder if there's anything like it available?

    Or do you have to examine the HOME environment variable?
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
  3. macrumors 68020

    Krevnik

    Joined:
    Sep 8, 2003
    #3
    The reason "/~/somefile.ext" doesn't work is because "~" cannot have anything before it on Unix.

    If you use "~/Library/Preferences/MyFile.ext", it will put the file in the current user's preferences folder. If you use "/~/Library/Preferences/MyFile.ext", it simply won't work.

    This is supported on every API on OS X that takes a file path.
     

Share This Page