Hello Guest

Simple SHGetSpecialFolderPath interface

  • 3 Replies
  • 11891 Views
*

Offline mot

  • **
  • 57
    • http://www.catnapgames.com
Simple SHGetSpecialFolderPath interface
« on: October 25, 2006, 23:04:09 »
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: http://www.catnapgames.com/download/WinFoldersJava.zip

Contact me here: tomovo@gmail.com


Cheers!
Tom
Tom Andrle - Catnap Games - http://www.catnapgames.com

*

Offline mot

  • **
  • 57
    • http://www.catnapgames.com
Re: Simple SHGetSpecialFolderPath interface
« Reply #1 on: January 12, 2007, 23:50:26 »
Tom Andrle - Catnap Games - http://www.catnapgames.com

Re: Simple SHGetSpecialFolderPath interface
« Reply #2 on: January 13, 2007, 11:07:34 »
isn't My Documents simply:

Quote
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?

DP

*

Offline mot

  • **
  • 57
    • http://www.catnapgames.com
Re: Simple SHGetSpecialFolderPath interface
« Reply #3 on: January 13, 2007, 11:45:36 »
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.
« Last Edit: January 13, 2007, 11:47:42 by mot »
Tom Andrle - Catnap Games - http://www.catnapgames.com