shell.NameSpace(path) returns null 当 path 是便携式设备的文件夹时

shell.NameSpace(path) returns null when path is a portable device's folder

我正在尝试将文件从一个路径移动到另一个路径,目标路径需要支持便携式设备,例如 android 手机。

发现 FolderBrowserDialog 不支持便携式设备后,我发现 this 博客解释了如何使用 Shell32COM-Objects

问题是我需要存储路径(字符串)并将其作为 Folder 对象加载回(从文件),这样做的方法是使用 shell 方法 shell.NameSpace(path)。 这只适用于系统路径,否则它将 return null:

 shell = new Shell();
 Folder folder = shell.BrowseForFolder((int) Handle, "Select folder", 0, 0);
 Folder folderFromPath = shell.NameSpace((folder as Folder3).Self.Path);
 //folderFromPath is null if I choose android device folder.

虽然这有效:

Folder folderFromPath = shell.NameSpace("C:\Program Files");
 //folderFromPath is not null

还有其他方法吗?

显然我的 android 设备生成了这条路径: ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\?\usb#vid_2717&pid_ff40#329682240804#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\SID-{10001,,54091657216}\{46DD6D4D-0000-0000-0000-000000000000}

将此路径传递给 shell.NameSpace 方法无效,但出于某些未知原因 删除 SID-{10001,,54091657216} 部分使其工作。

我真的不知道这部分是什么意思(虽然它是设备内部存储的参考),哪些设备生成它,而且,为什么没有其他人发布。

但是如果其他人遇到这个问题,我希望这会有所帮助:)。