/// <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); }
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); } } }
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); }
/// <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); }