Simple SHGetSpecialFolderPath interface

Started by mot, October 25, 2006, 23:04:09

Previous topic - Next topic


All we get in Java is user.home, which usually points to something like
C:\Documents and Settings\user\
while I want this:
C:\Documents and Settings\user\My documents\

In the win32 API, the My documents path or Desktop or other special Windows locations can be retrieved using the SHGetSpecialFolderPath() function. So I created a simple interface to access SHGetSpecialFolderPath in Java. Not thoroughly tested yet and also my first JNI encounter, so don't kick me, alright?

Here it is with full source code and Visual Studio 2003 solution files:

Contact me here:

Tom Andrle - Catnap Games -


Tom Andrle - Catnap Games -


isn't My Documents simply:

File f = new File(System.getProperty("user.home") + "\My Documents\");

just replace My Documents with Desktop if you really want the Desktop? Or am I missing something?



Yes, indeed you are missing something. This will only work in the English version of Windows XP. Vista has a different folder structure and any Windows in any other language have a different name for the folders. So you absolutely need to call the API function to get the correct location.
Tom Andrle - Catnap Games -