3

The Apache Commons VFS library appears to be unable to support special Windows folders (Network, recent, computer, libraries, etc).

File[] cbFolders = (File[])sun.awt.shell.ShellFolder.get("fileChooserComboBoxFolders");

and then converting them to FileObjects like so:

for(File f: cbFolders){
    fileObjArray.add(mgr.resolveFile(f.getPath()));
}

It just doesn't work and all you get is the path name for its name.

The path of these files are like ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}

Any help in getting this working would be appreciated. It looks like its most likely a bug in the library. Hopefully someone knows of a hack or such to get it working.

Edit: I believe I was close when I created new shortcuts

try{
    final File[] cbFolders = (File[])sun.awt.shell.ShellFolder.get("fileChooserComboBoxFolders");

    String name = "";

    File[] systemFiles = new File[cbFolders.length];
    i =0;
    for(File f: cbFolders){
        name = f.getName();
        if(name.startsWith("::{")){
            name = name.substring(2);
            System.out.println("converting: " + name);
            String fileName = fileSystemView.getSystemDisplayName(f);

            File file = new File("C:\\Users\\Daniel\\Desktop\\" + fileName + "." + name);

            boolean success = false;
            success = file.mkdir(); //returns false even if it works,

            systemFiles[i] = file;
        }else
            systemFiles[i] = f;
        i++;
    }

    list = new ArrayList<File>(Arrays.asList(systemFiles));
}catch(final Exception e){
    ...
}

It shows the correct icon and name and on Windows Explorer it opens correctly, but still with VFS it opens an empty folder.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Daniel Ryan
  • 6,976
  • 5
  • 45
  • 62
  • Wow! I have never used the ShellFolder class. How did you find it? How did you know that you have to send parameter "fileChooserComboBoxFolders"? I am sorry that I am asking a questing instead of give you an answer. I do not have answer but the issue is interesting to me. – AlexR Nov 24 '10 at 07:48
  • I just do not understand what is the relationship between the title and the question itself. Commons VFS' package is org.apache.commons.vfs while you are using sun.awt.shell. – AlexR Nov 24 '10 at 07:55
  • "How did you find it?" Hardcore searching on google :) "How did you know that you have to send parameter "fileChooserComboBoxFolders"?" Java Source code. "I just do not understand what is the relationship between the title and the question itself." I want to get VFS to support special files, by default it can't handle the path names of these special files. – Daniel Ryan Nov 25 '10 at 04:18
  • There is no real support for this, but just to mention it, using File#getPath() for resolveFile() is not correct as it does not do URL escaping. file.toURI().toString() should work better. – eckes Jan 05 '15 at 23:49

1 Answers1

1

There is no real support for those files. The main problem is that neither the Java File object treats them correctly (new File("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}").toURI().toString() does not properly escape the colons) nor is Java or VFS knowing about :: as an absolute filesystem root. So you cannot transform them into a URI (required by resolveFile()) which keeps the special properties recognized by Windows.

eckes
  • 10,103
  • 1
  • 59
  • 71
  • This is quite an old question now. This was before Java 7 which improved everything in this area. I could get Java 6 to handle those files just fine but never VFS. I used my code in some areas and VFS in others. It was quite hacky :) – Daniel Ryan Jan 06 '15 at 22:48