Exemplo n.º 1
0
        internal static int TryGetDirectoryAttributes(string normalizedPath, out FileAttributes attributes)
        {
            int errorCode = TryGetFileAttributes(normalizedPath, out attributes);

            if (!LongPathDirectory.IsDirectory(attributes))
            {
                errorCode = NativeMethods.ERROR_DIRECTORY;
            }

            return(errorCode);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates the specified directory.
        /// </summary>
        /// <param name="path">
        ///     A <see cref="String"/> containing the path of the directory to create.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="path"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="path"/> is an empty string (""), contains only white
        ///     space, or contains one or more invalid characters as defined in
        ///     <see cref="Path.GetInvalidPathChars()"/>.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> contains one or more components that exceed
        ///     the drive-defined maximum length. For example, on Windows-based
        ///     platforms, components must not exceed 255 characters.
        /// </exception>
        /// <exception cref="PathTooLongException">
        ///     <paramref name="path"/> exceeds the system-defined maximum length.
        ///     For example, on Windows-based platforms, paths must not exceed
        ///     32,000 characters.
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     <paramref name="path"/> contains one or more directories that could not be
        ///     found.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        ///     The caller does not have the required access permissions.
        /// </exception>
        /// <exception cref="IOException">
        ///     <paramref name="path"/> is a file.
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="path"/> specifies a device that is not ready.
        /// </exception>
        /// <remarks>
        ///     Note: Unlike <see cref="Directory.CreateDirectory(System.String)"/>, this method only creates
        ///     the last directory in <paramref name="path"/>.
        /// </remarks>
        public static void Create(string path)
        {
            string normalizedPath = LongPathCommon.NormalizeLongPath(path);

            if (!NativeMethods.CreateDirectory(normalizedPath, IntPtr.Zero))
            {
                // To mimic Directory.CreateDirectory, we don't throw if the directory (not a file) already exists
                int errorCode = Marshal.GetLastWin32Error();
                if (errorCode != NativeMethods.ERROR_ALREADY_EXISTS || !LongPathDirectory.Exists(path))
                {
                    throw LongPathCommon.GetExceptionFromWin32Error(errorCode);
                }
            }
        }
Exemplo n.º 3
0
        internal static bool Exists(string path, out bool isDirectory)
        {
            string normalizedPath;

            if (TryNormalizeLongPath(path, out normalizedPath))
            {
                FileAttributes attributes;
                int            errorCode = TryGetFileAttributes(normalizedPath, out attributes);
                if (errorCode == 0)
                {
                    isDirectory = LongPathDirectory.IsDirectory(attributes);
                    return(true);
                }
            }

            isDirectory = false;
            return(false);
        }