private void AddMatches(NtDirectory root, string base_path, IEnumerable <string> remaining, List <string> matches)
        {
            string current_entry = remaining.First();
            bool   is_leaf       = remaining.Count() == 1;
            List <ObjectDirectoryInformation> matching_entries = new List <ObjectDirectoryInformation>();

            if (root.IsAccessGranted(DirectoryAccessRights.Query))
            {
                // If this is not a leaf point we don't care about non-directory entries.
                ObjectDirectoryInformation[] dir_infos = root.Query().Where(d => is_leaf || d.IsDirectory).ToArray();
                foreach (ObjectDirectoryInformation dir_info in dir_infos)
                {
                    if (dir_info.Name.Equals(current_entry, StringComparison.OrdinalIgnoreCase))
                    {
                        matching_entries.Add(dir_info);
                        break;
                    }
                }

                // If we didn't find an explicit match then see if it's a glob.
                if (matching_entries.Count == 0 && HasGlobChars(current_entry))
                {
                    Regex globber = GlobToRegex(current_entry, false);
                    foreach (ObjectDirectoryInformation dir_info in dir_infos)
                    {
                        if (globber.IsMatch(dir_info.Name))
                        {
                            matching_entries.Add(dir_info);
                        }
                    }
                }
            }

            // Nothing matched.
            if (matching_entries.Count == 0)
            {
                return;
            }

            // We've reached the end of the road.
            if (is_leaf)
            {
                foreach (ObjectDirectoryInformation dir_info in matching_entries)
                {
                    string full_path = base_path + dir_info.Name;
                    _item_cache[full_path] = new NtDirectoryEntry(GetDrive().DirectoryRoot, PSPathToNT(full_path), dir_info.Name, dir_info.TypeName);
                    matches.Add(full_path);
                }
            }
            else
            {
                foreach (ObjectDirectoryInformation entry in matching_entries)
                {
                    try
                    {
                        using (NtDirectory dir = NtDirectory.Open(entry.Name, root, DirectoryAccessRights.Query))
                        {
                            AddMatches(dir, base_path + entry.Name + @"\", remaining.Skip(1), matches);
                        }
                    }
                    catch (NtException)
                    {
                    }
                }
            }
        }
        private void AddMatches(NtDirectory root, string base_path, IEnumerable<string> remaining, List<string> matches)
        {
            string current_entry = remaining.First();
            bool is_leaf = remaining.Count() == 1;
            List<ObjectDirectoryInformation> matching_entries = new List<ObjectDirectoryInformation>();
            
            if (root.IsAccessGranted(DirectoryAccessRights.Query))
            {
                // If this is not a leaf point we don't care about non-directory entries.
                ObjectDirectoryInformation[] dir_infos = root.Query().Where(d => is_leaf || d.IsDirectory).ToArray();
                foreach (ObjectDirectoryInformation dir_info in dir_infos)
                {
                    if (dir_info.Name.Equals(current_entry, StringComparison.OrdinalIgnoreCase))
                    {                        
                        matching_entries.Add(dir_info);
                        break;
                    }
                }

                // If we didn't find an explicit match then see if it's a glob.
                if (matching_entries.Count == 0 && HasGlobChars(current_entry))
                {
                    Regex globber = GlobToRegex(current_entry, false);
                    foreach (ObjectDirectoryInformation dir_info in dir_infos)
                    {
                        if (globber.IsMatch(dir_info.Name))
                        {
                            matching_entries.Add(dir_info);
                        }
                    }
                }
            }

            // Nothing matched.
            if (matching_entries.Count == 0)
            {
                return;
            }

            // We've reached the end of the road.
            if (is_leaf)
            {
                foreach (ObjectDirectoryInformation dir_info in matching_entries)
                {
                    string full_path = base_path + dir_info.Name;
                    _item_cache[full_path] = new NtDirectoryEntry(GetDrive().DirectoryRoot, PSPathToNT(full_path), dir_info.Name, dir_info.TypeName);
                    matches.Add(full_path);
                }
            }
            else
            {
                foreach (ObjectDirectoryInformation entry in matching_entries)
                {
                    try
                    {
                        using (NtDirectory dir = NtDirectory.Open(entry.Name, root, DirectoryAccessRights.Query))
                        {
                            AddMatches(dir, base_path + entry.Name + @"\", remaining.Skip(1), matches);
                        }
                    }
                    catch (NtException)
                    {
                    }
                }
            }
        }