예제 #1
0
        /// <summary>
        /// Determines the type based on the attributes of the path
        /// </summary>
        /// <param name="fullPath">Full path</param>
        /// <returns><see cref="QuickIOFileSystemEntryType"/></returns>
        internal static QuickIOFileSystemEntryType DetermineFileSystemEntry(string fullPath)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(fullPath));

            Win32FindData findData = InternalQuickIO.GetFindDataFromPath(fullPath);

            return(!InternalHelpers.ContainsFileAttribute(findData.dwFileAttributes, FileAttributes.Directory) ? QuickIOFileSystemEntryType.File : QuickIOFileSystemEntryType.Directory);
        }
예제 #2
0
        public static Win32FindData GetFindDataFromPath(string fullpath, QuickIOFileSystemEntryType?estimatedFileSystemEntryType = null)
        {
            Contract.Requires(fullpath != null);
            //Changed to allow paths which do not exist:
            //Contract.Ensures( Contract.Result<Win32FindData>() != null );
            if (!QuickIOPath.Exists(fullpath))
            {
                return(null);
            }
            Win32FindData win32FindData = SafeGetFindDataFromPath(fullpath);

            if (win32FindData == null)
            {
                //Changed to allow paths which do not exist:
                //throw new PathNotFoundException( fullpath );
                return(null);
            }

            // Check for correct type
            switch (estimatedFileSystemEntryType)
            {
            case QuickIOFileSystemEntryType.Directory:
            {
                // Check for directory flag
                if (InternalHelpers.ContainsFileAttribute(win32FindData.dwFileAttributes, FileAttributes.Directory))
                {
                    return(win32FindData);
                }
                throw new UnmatchedFileSystemEntryTypeException(QuickIOFileSystemEntryType.Directory, QuickIOFileSystemEntryType.File, fullpath);
            }

            case QuickIOFileSystemEntryType.File:
            {
                // Check for directory flag
                if (!InternalHelpers.ContainsFileAttribute(win32FindData.dwFileAttributes, FileAttributes.Directory))
                {
                    return(win32FindData);
                }
                throw new UnmatchedFileSystemEntryTypeException(QuickIOFileSystemEntryType.File, QuickIOFileSystemEntryType.Directory, fullpath);
            }

            case null:
            default:
            {
                return(win32FindData);
            }
            }
        }
예제 #3
0
        public static bool FileExists(string path)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(path));

            int win32Error;
            var attrs = InternalQuickIO.SafeGetAttributes(path, out win32Error);

            if (Equals(attrs, 0xffffffff))
            {
                return(false);
            }

            if (!InternalHelpers.ContainsFileAttribute(FileAttributes.Directory, ( FileAttributes )attrs))
            {
                return(true);
            }

            throw new UnmatchedFileSystemEntryTypeException(QuickIOFileSystemEntryType.File, QuickIOFileSystemEntryType.Directory, path);
        }
예제 #4
0
        /// <summary>
        /// Determines the type based on the attributes of the handle
        /// </summary>
        /// <param name="findData"><see cref="Win32FindData"/></param>
        /// <returns><see cref="QuickIOFileSystemEntryType"/></returns>
        internal static QuickIOFileSystemEntryType DetermineFileSystemEntry(Win32FindData findData)
        {
            Contract.Requires(findData != null);

            return(!InternalHelpers.ContainsFileAttribute(findData.dwFileAttributes, FileAttributes.Directory) ? QuickIOFileSystemEntryType.File : QuickIOFileSystemEntryType.Directory);
        }