如何在 C# 中检测 NTFS 挂载的文件夹?

发布于 2024-07-13 02:57:59 字数 118 浏览 7 评论 0原文

曾几何时,我读到如何以编程方式检测已安装的 NTFS 文件夹(在搜索文件夹时可能会导致循环递归)。 现在我找不到链接..有谁知道该怎么做?

我有兴趣检测的安装是一个文件夹安装到另一个文件夹时的情况。

Once upon a time I read how you detect programmatically for mounted NTFS folders (can cause cyclic recursion when searching through folders). Now i cannot find the link.. Does anyone know how to do this?

The mounting I am interested in detecting is when one folder is mounted to another folder.

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

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

发布评论

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

评论(2

你与昨日 2024-07-20 02:57:59

我假设您指的是 NTFS 连接? 有一个 非托管 API 来进行重新解析点,然后您必须询问才能看看它是否真的是一个路口。 当然,这一切都可以通过 P/Invoke 获得。

但是,大多数人只是(1)寻找 ReparsePoint 在返回的属性列表中DirectoryInfo.GetDirectories

(1) 请注意,NTFS 连接点是一种特定类型的重分析点,但不是唯一的。 符号链接、硬链接(2) 和任何其他用户定义的数据也是重分析点。

(2)哎呀。 硬链接不是重新分析点,它们只是指向相同的文件。 感谢 Reuben 纠正我的错误。

I assume you mean a NTFS junction? There is an unmanaged API to get the reparse point, which you then have to interrogate to see if it's actually a junction. This is all available through P/Invoke, of course.

But, most folks just(1) look for ReparsePoint on the list of attributes returned by DirectoryInfo.GetDirectories.

(1) Note that a NTFS Junction is a particular type of reparse point, but not the only one. Symbolic links, hard links,(2) and any other user defined data are also reparse points.

(2) Whoops. Hard links aren't reparse points, they're just standard directory entries pointing to the same file. Thanks to Reuben for correcting me on that.

清欢 2024-07-20 02:57:59

通过 WMI 执行此操作。 请参阅示例:http://msdn.microsoft.com /en-us/library/aa393244(VS.85).aspx

或者尝试使用 WMI 代码创建器


using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\\CIMV2", 
                    "SELECT * FROM Win32_DiskPartition"); 

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_DiskPartition instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Type: {0}", queryObj["Type"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}

Do this via WMI. See sample at : http://msdn.microsoft.com/en-us/library/aa393244(VS.85).aspx

Or try this sample code made with WMI Code Creator:


using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\\CIMV2", 
                    "SELECT * FROM Win32_DiskPartition"); 

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_DiskPartition instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Type: {0}", queryObj["Type"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文