Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-Shell.Namespace(pathFolder)返回null,即使是<;路径文件夹>;存在_C#_Windows_Recursion_Filesystems_Shell32 - Fatal编程技术网

C#-Shell.Namespace(pathFolder)返回null,即使是<;路径文件夹>;存在

C#-Shell.Namespace(pathFolder)返回null,即使是<;路径文件夹>;存在,c#,windows,recursion,filesystems,shell32,C#,Windows,Recursion,Filesystems,Shell32,我尝试使用以下代码通过“开始菜单”文件夹进行递归循环: Function(string pathFolder) { Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder folderObj = shell.NameSpace(pathFolder); foreach ( Shell32.FolderItem2 item in objFolder.Items() ) { string typeItem = folderOb

我尝试使用以下代码通过“开始菜单”文件夹进行递归循环:

Function(string pathFolder) {

Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder folderObj = shell.NameSpace(pathFolder);

foreach ( Shell32.FolderItem2 item in objFolder.Items() ) {

    string typeItem = folderObj.GetDetailsOf(item, 2);

    if ( typeItem == "File folder" ) {

        string folderName = folderObj.GetDetailsOf(item, 0);
        Function(pathFolder + "\\" + folderName);

    } else {
        // do smomething...
    }
}
问题是Shell.Namespace对某些文件夹(而不是所有文件夹)运行良好。对于那些不工作的文件夹,即使这些文件夹确实存在,Shell.Namespace也会返回null


我的代码怎么了?

为什么不使用System.IO命名空间类?我认为它有更高级的API。对于您的情况,这可能是安全问题。

为什么不使用System.IO命名空间类?我认为它有更高级的API。对于您的情况,这可能是安全问题。

这是因为我想使用Shell对象的GetDetailsOf()方法来检索其他文件的信息,例如:快捷链接的目标路径。哦,从来没有想过它们(.在任何情况下,您都可以尝试使用System.IO类来检查这些非工作文件夹,或者找出它们是否引发任何异常。您是对的。对于我的情况,使用System.IO.Directory要容易得多,我只是以前没有想过。谢谢!无论如何,对我的问题有什么建议吗?因为我想使用GetDetailsOf()Shell对象的方法来检索其他文件的信息,例如:快捷链接的目标路径。哦,从来没有想过它们(.在任何情况下,您都可以尝试使用System.IO类来检查这些非工作文件夹,或者找出它们是否引发任何异常。您是对的。对于我的情况,使用System.IO.Directory要容易得多,我只是以前没有想过。谢谢!无论如何,对我的问题有什么建议吗?