开发者

Getting Special folders to work in Apache Commons VFS

开发者 https://www.devze.com 2023-01-27 05:04 出处:网络
The Apache Commons VFS library appears to be unable to support special Windows folders (Network, recent, computer, libraries, etc).

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消