Application Directory?

This is a discussion on Application Directory? within the Windows Programming forums, part of the Platform Specific Boards category; My app needs to create a directory to store some files it uses. Is there a standard place to do ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    9

    Question Application Directory?

    My app needs to create a directory to store some files it uses. Is there a standard place to do this under Win32? (I mostly program Mac OS X where the answer to this question is ~/Library/Application Support/)

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    Windows uses \Temp directory to store temporary files.

    You can also store some application related information to registry in windows but it is not a proper place to store files.

    Otherwise select directory your self and store your files within that directory.
    Chintan R Naik

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    9
    Thanks. I use the registry to store preferences data, but these files are several 100k. I'm currently creating a directory in the user's home directory and putting them in it. I guess that's OK for Windows.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Windows defines a directory for user application data, whose path you can look for in the registry. The Temp folder is intended for files that will be created, used, and then deleted afterwards.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    9
    What registry entry should be used? HKEY_CURRENT_USER\Volatile Environment\APPDATA? Is it consistent over all Win32 platforms?

    Thanks, Nick

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    9
    Thanks Hammer, but isn't that only for temporary files? I'm looking for a place to store application data (some of which are largish files that persist between launches).

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Yeah, sorry, I kinda missed your point there

    How about this one instead:
    http://msdn.microsoft.com/library/de...tallations.asp
    Any good?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    Here's code that may be relevant:

    Code:
    }
    BOOL GetShellFolderPath(char * pShellFolder, char * pShellPath) {
     // pShellFolder can be one of the following
     // AppData, Cache, Cookies, Desktop, Favorites,
     // Fonts, History, NetHood,
     // Personal, Printhood, Programs, Recent,
     // SendTo, Start Menu, Startup,
     // Templates, ShellNew
     DWORD rc;
     DWORD length = MAX_PATH;
     DWORD type = REG_SZ;
     HKEY hkey;
     
     rc = RegOpenKeyEx(HKEY_CURRENT_USER,
                       "Software\\Microsoft\\Windows\\CurrentVersion\\"
                       "Explorer\\Shell Folders",
                       0, KEY_READ, &hkey);
                       
     if (rc == ERROR_SUCCESS) {
      rc = RegQueryValueEx(hkey, pShellFolder, NULL, &type,
                           (BYTE *) pShellPath, &length);
      RegCloseKey(hkey);
     }
     
     if (rc == ERROR_SUCCESS)
      return TRUE;
     else
      return FALSE;
    }

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    9
    Thank you Poccil and Hammer! Based on the MSDN article and the sample code, I was able to get this to work. The path is HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\Shell Folders and the key is AppData.

  11. #11
    id id
    Guest
    For reference SHGetFolderPath is the recommended function to get folder locations. However for backwards compatibility one must include the 22KB redistributable Shfolder.dll with an application.

    This should be more reliable than reading the registry directly.

    See:
    http://msdn.microsoft.com/library/en...folderpath.asp

    http://www.mvps.org/vbnet/index.html...owse/csidl.htm

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    76
    That's true. Perhaps the best solution is to dynamically link to shfolder.dll, or check the registry if the file doesn't exist.

  13. #13
    Registered User
    Join Date
    Jun 2003
    Posts
    9
    Sounds like it might be better for native apps.
    My app is actually Java with a little platform-specific code to handle these sort of issues. It turns out that I can use existing code to get access to the registry, which avoids the problems of DLL's, native methods, etc. So I'm sticking with what I've got - so far it tests out fine.
    Thanks everyone.

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. Get Application Directory
    By cppnewbie81 in forum C++ Programming
    Replies: 15
    Last Post: 07-11-2007, 05:57 AM
  4. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  5. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 08:43 AM

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