import com.ms.dll.DllLib; public class browse { /** @dll.import("shell32") */ static native int SHBrowseForFolder(BROWSEINFO bi); /** @dll.import("shell32") */ static native boolean SHGetPathFromIDList(int pidl, StringBuffer path); static final int BIF_VALIDATE = 0x0020; static final int BIF_RETURNONLYFSDIRS = 0x0001; static final int BUFSIZ = 1024; public String browseForFolder(String message) { BROWSEINFO bi = new BROWSEINFO(); if (message != null) bi.lpszTitle = message; bi.ulFlags = BIF_VALIDATE | BIF_RETURNONLYFSDIRS; int pidl = SHBrowseForFolder(bi); if (pidl <= 0) { return null; } else { StringBuffer buf = new StringBuffer(BUFSIZ); if (SHGetPathFromIDList(pidl, buf)) { return buf.toString(); } return null; } } public static void main(String args[]) { System.out.println(new browse().browseForFolder(args[0])); } } /** @dll.struct() */ class BROWSEINFO { public int hwndOwner; public int pidlRoot; public String pszDisplayName;// Return display name of item selected. public String lpszTitle; // text to go in the banner over the tree. public int ulFlags;// Flags that control the return stuff public int lpfn; public int lParam; // extra info that's passed back in callbacks public int iImage; // output var: where to return the Image index. }