Programmatic access to current user's folder

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

  1. Kurukuru Guest

    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. robbieduncan Moderator emeritus


    Jul 24, 2002
  3. Krevnik macrumors 68040


    Sep 8, 2003
    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