Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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);
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top