Пример #1
0
        /// <summary>
        /// Get the type of a directory entry by path.
        /// </summary>
        /// <param name="path">The path to the directory entry</param>
        /// <param name="root">The root object to look up if path is relative</param>
        /// <returns>The type name, or null if it can't be found.</returns>
        public static string GetDirectoryEntryType(string path, NtObject root)
        {
            if (root == null && path == @"\")
            {
                return("Directory");
            }

            string dir_name = GetDirectoryName(path);

            if (dir_name == string.Empty && root == null)
            {
                dir_name = @"\";
            }
            using (var dir = Open(dir_name, root, DirectoryAccessRights.Query, false))
            {
                if (dir.IsSuccess)
                {
                    ObjectDirectoryInformation dir_info = dir.Result.GetDirectoryEntry(GetFileName(path));
                    if (dir_info != null)
                    {
                        return(dir_info.NtTypeName);
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Get the type of a directory entry by path.
        /// </summary>
        /// <param name="path">The path to the directory entry</param>
        /// <param name="root">The root object to look up if path is relative</param>
        /// <returns>The type name, or null if it can't be found.</returns>
        public static string GetDirectoryEntryType(string path, NtObject root)
        {
            if (root == null && path == @"\")
            {
                return("Directory");
            }

            try
            {
                using (NtDirectory dir = NtDirectory.Open(GetDirectoryName(path), root, DirectoryAccessRights.Query))
                {
                    ObjectDirectoryInformation dir_info = dir.GetDirectoryEntry(GetFileName(path));
                    if (dir_info != null)
                    {
                        return(dir_info.TypeName);
                    }
                }
            }
            catch (NtException)
            {
            }

            return(null);
        }