让特殊文件夹在 Apache Commons VFS 中工作

发布于 2024-10-03 18:21:41 字数 1462 浏览 1 评论 0原文

Apache Commons VFS 库似乎无法支持特殊的 Windows 文件夹(网络、最近、计算机、库等)。

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

然后将它们转换为 FileObjects,如下所示:

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

它只是不起作用,您得到的只是其名称的路径名。

这些文件的路径类似于 ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}

任何帮助实现此工作的帮助将不胜感激。它看起来很可能是库中的错误。希望有人知道黑客之类的东西才能使其正常工作。

编辑: 我相信当我创建新的快捷方式时我已经很接近了

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){
    ...
}

它显示了正确的图标和名称,并且在 Windows 资源管理器上它可以正确打开,但仍然使用 VFS 它会打开一个空文件夹。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2024-10-10 18:21:41

这些文件没有真正的支持。主要问题是 Java File 对象都没有正确对待它们(new File("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}").toURI().toString() 没有Java 或 VFS 也不知道 :: 作为绝对文件系统根。因此,您无法将它们转换为 URI(resolveFile() 所需的),从而保留 Windows 识别的特殊属性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文