识别坏ReparsePoints与GetDirectories()在.NET 3.5中? [英] Identifying bad ReparsePoints with GetDirectories() in .Net 3.5?

查看:170
本文介绍了识别坏ReparsePoints与GetDirectories()在.NET 3.5中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Directory.GetDirectories()通过一个文件夹中所没有的系统文件夹中的所有目录中的LINQ的声明中循环,但是我发现了一堆坏 ReparsePoints 的文件夹,这是造成该方法需要很长的时间,因为它在超时每个坏的重新分析点。

I am using Directory.GetDirectories() with a Linq statement to loop through all directories in a folder that aren't system folders, however I am discovering a bunch of bad ReparsePoints in the folder, which is causing the method to take a long time as it times out on each bad reparse point.

在code我目前使用看起来像这样:

The code I am currently using looks like this:

subdirectories = directory.GetDirectories("*", SearchOption.TopDirectoryOnly)
    .Where(d => ((d.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
         && ((d.Attributes & FileAttributes.System) != FileAttributes.System));

我也尝试过使用code这样的测试,但它也挂起了一分钟左右就坏了文件夹:

I have also tried using code like this for testing, but it also hangs for a full minute or so on the bad folders:

foreach (var item in dir.GetDirectories("*", SearchOption.TopDirectoryOnly))
{
    Console.WriteLine(item.Name);
    Console.WriteLine(item.Attributes);
}

应当指出的是,code以上位工作正常,在.NET 4.0中,但在3.5,将挂起对每个坏重新分析点一分钟。

It should be noted that the above bit of code works fine in .Net 4.0, but in 3.5 it will hang for a minute on each bad reparse point.

试图在Windows资源管理器导致手动打开这些文件夹找不到网络路径错误。

Trying to open these folders manually in Windows Explorer results in a "Network Path Not Found" error.

有另一种方式,通过一个文件夹内良好的子文件夹,不使用属性财产循环,或绕过坏的重分析点?

Is there another way to loop through good subfolders inside a folder that doesn't use the Attributes property, or that bypasses the bad reparse points?

我已经尝试过使用 Directory.Exists(),这同样是缓慢的。

I have already tried using Directory.Exists(), and that is equally slow.

推荐答案

根据这样的回答:<一href="http://stackoverflow.com/questions/3582823/fastest-directory-listing/8827241#8827241">*FASTEST*目录列表

为了获得最佳性能,有可能的P / Invoke NtQueryDirectoryFile ,记录为 ZwQueryDirectoryFile

For the best performance, it is possible to P/Invoke NtQueryDirectoryFile, documented as ZwQueryDirectoryFile

从MSDN: FILE_REPARSE_POINT_INFORMATION 结构

From MSDN: FILE_REPARSE_POINT_INFORMATION structure

这信息可通过以下任一方式进行查询:

This information can be queried in either of the following ways:

呼叫 ZwQueryDirectoryFile ,通过 FileReparsePointInformation 作为FileInformationClass的价值,并通过调用者分配, FILE_REPARSE_POINT_INFORMATION -structured缓冲区 FileInformation 的价值。

Call ZwQueryDirectoryFile, passing FileReparsePointInformation as the value of FileInformationClass and passing a caller-allocated, FILE_REPARSE_POINT_INFORMATION-structured buffer as the value of FileInformation.

创建与主要功能code的 IRP_MJ_DIRECTORY_CONTROL 和次要功能code IRP_MN_QUERY_DIRECTORY

Create an IRP with major function code IRP_MJ_DIRECTORY_CONTROL and minor function code IRP_MN_QUERY_DIRECTORY.

这篇关于识别坏ReparsePoints与GetDirectories()在.NET 3.5中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆