/// <summary>
        /// Gets the <see cref="Win32FindData"/> from the passed path.
        /// </summary>
        /// <param name="fullpath">Path</param>
        /// <param name="win32FindData"><seealso cref="Win32FindData"/>. Will be null if path does not exist.</param>
        /// <returns>true if path is valid and <see cref="Win32FindData"/> is set</returns>
        /// <remarks>
        /// <see>
        ///     <cref>QuickIOCommon.NativeExceptionMapping</cref>
        /// </see> if invalid handle found.
        /// </remarks>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        public static bool TryGetFindDataFromPath( string fullpath, out Win32FindData win32FindData )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( fullpath ) );

            win32FindData = GetFindDataFromPath( fullpath );
            return ( win32FindData != null );
        }
        /// <summary>
        /// Returns the <see cref="Win32FileHandle"/> and fills <see cref="Win32FindData"/> from the passes path.
        /// </summary>
        /// <param name="path">Path to the file system entry</param>
        /// <param name="win32FindData"></param>
        /// <param name="win32Error">Last error code. 0 if no error occurs</param>
        /// <returns><see cref="Win32FileHandle"/></returns>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        private static Win32FileHandle FindFirstSafeFileHandle( string path, Win32FindData win32FindData, out Int32 win32Error )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( path ) );

            Contract.Ensures( Contract.Result<Win32FileHandle>() != null );

            var result = Win32SafeNativeMethods.FindFirstFile( path, win32FindData );
            win32Error = Marshal.GetLastWin32Error();

            return result;
        }
        /// <summary>
        /// Initializes a new instance of the QuickIOAbstractBase class, which acts as a wrapper for a file path.
        /// </summary>
        /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param>
        /// <param name="findData"><see cref="Win32FindData"/></param>
        internal QuickIOFileSystemEntryBase( QuickIOPathInfo pathInfo, Win32FindData findData )
        {
            this.PathInfo = pathInfo;
            this.FindData = findData;
            if( findData != null )
            {
                this.Attributes = findData.dwFileAttributes;
            }

            _lastWriteTimeUtc = FindData.GetLastWriteTimeUtc();
            _lastAccessTimeUtc = findData.GetLastAccessTimeUtc();
            _creationTimeUtc = findData.GetCreationTimeUtc();
        }
        internal QuickIOFileSystemMetadataBase( string fullPath, Win32FindData win32FindData)
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( fullPath ) );
            Contract.Requires( win32FindData != null );

            FindData = win32FindData;

            FullNameUnc = QuickIOPath.ToPathUnc( fullPath );
            FullName = QuickIOPath.ToPathRegular( fullPath );

            this.LastWriteTimeUtc = win32FindData.GetLastWriteTimeUtc();
            this.LastAccessTimeUtc = win32FindData.GetLastAccessTimeUtc();
            this.CreationTimeUtc = win32FindData.GetCreationTimeUtc();

            Name = win32FindData.cFileName;

            Attributes = win32FindData.dwFileAttributes;
        }
        /// <summary>
        /// Creates the path information container
        /// </summary>
        /// <param name="fullpath">Full path to the file or directory (regular or unc)</param>
        /// <param name="win32FindData">Win32 handle information</param>
        internal QuickIOPathInfo( string fullpath, Win32FindData win32FindData )
        {
            Contract.Requires( fullpath != null );
            Contract.Requires( win32FindData != null );

            this.FindData = win32FindData;


            this.Name = QuickIOPath.GetName( fullpath );
            this.FullName = QuickIOPath.ToPathRegular( fullpath );
            this.FullNameUnc = QuickIOPath.ToPathUnc( fullpath );

            // TODO:
            this.Parent = QuickIOPath.GetDirectoryName( fullpath );
            this.Root = QuickIOPath.GetPathRoot( fullpath );

            this.IsRoot = QuickIOPath.IsRoot( fullpath );
        }
 /// <summary>
 /// Creates instance of <see cref="QuickIODirectoryMetadata"/>
 /// </summary>
 /// <param name="win32FindData">Win32FindData of current directory</param>
 /// <param name="subDirs">Directories in current directory</param>
 /// <param name="subFiles">Files in current directory</param>
 /// <param name="uncFullname">UNC Path of current directory</param>
 internal QuickIODirectoryMetadata( string uncFullname, Win32FindData win32FindData, IList<QuickIODirectoryMetadata> subDirs, IList<QuickIOFileMetadata> subFiles )
     : base( uncFullname , win32FindData )
 {
     Directories = new ReadOnlyCollection<QuickIODirectoryMetadata>( subDirs );
     Files = new ReadOnlyCollection<QuickIOFileMetadata>( subFiles );
 }
 /// <summary>
 /// Returns true if entry is a file
 /// </summary>
 /// <remarks>Checks <see cref="FileAttributes.Directory"/></remarks>
 public static Boolean IsFile(this Win32FindData source)
 {
     return(!IsDirectory(source));
 }
 /// <summary>
 /// Creates the file information on the basis of the path and <see cref="Win32FindData"/>
 /// </summary>
 /// <param name="pathInfo">Full path to the file</param>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 internal QuickIOFileInfo( QuickIOPathInfo pathInfo, Win32FindData win32FindData )
     : base( pathInfo, win32FindData )
 {
     
 }
 /// <summary>
 /// Creates the file information on the basis of the path and <see cref="Win32FindData"/>
 /// </summary>
 /// <param name="fullName">Full path to the file</param>
 /// <param name="win32FindData"><see cref="Win32FindData"/></param>
 internal QuickIOFileInfo( String fullName, Win32FindData win32FindData )
     : this( new QuickIOPathInfo( fullName ), win32FindData )
 {
    
 }
 public Win32FileSystemEntry( Win32FileHandle fileHandle, Win32FindData findData )
 {
     FileHandle = fileHandle;
     FindData = findData;
 }
 /// <summary>
 /// Returns total size of entry in Bytes
 /// </summary>
 public static ulong GetBytes(this Win32FindData source)
 {
     return(( ulong )source.nFileSizeHigh << 32 | source.nFileSizeLow);
 }
        ///// <summary>
        ///// Returns the <see cref="Win32FindData"/> from specified <paramref name="fullUncPath"/>
        ///// </summary>
        ///// <param name="fullUncPath">Path to the file system entry</param>
        ///// <returns><see cref="Win32FindData"/></returns>
        ///// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        /// 
        /// <summary>
        /// Returns the <see cref="Win32FindData"/> from specified <paramref name="fullpath"/>
        /// </summary>
        /// <param name="fullpath">Path to the file system entry</param>
        /// <returns><see cref="Win32FindData"/></returns>
        public static Win32FindData SafeGetFindDataFromPath( string fullpath )
        {
            Contract.Requires( !String.IsNullOrWhiteSpace( fullpath ) );

            Win32FindData win32FindData = new Win32FindData();
            int win32Error;
            using( Win32FileHandle fileHandle = FindFirstSafeFileHandle( fullpath, win32FindData, out win32Error ) )
            {
                // Take care of invalid handles
                if( fileHandle.IsInvalid )
                {
                    Win32ErrorCodes.NativeExceptionMapping( fullpath, win32Error );
                }

                // Treffer auswerten
                // Ignore . and .. directories
                if( !win32FindData.IsSystemDirectoryEntry() )
                {
                    return win32FindData;
                }
            }

            return null;
        }
 /// <summary>
 /// Returns true if entry is a directory
 /// </summary>
 /// <remarks>Checks <see cref="FileAttributes.Directory"/></remarks>
 public static Boolean IsDirectory(this Win32FindData source)
 {
     return((source.dwFileAttributes & FileAttributes.Directory) != 0);
 }
        /// <summary>
        /// Creates the folder information on the basis of the path and the handles
        /// </summary>
        /// <param name="fullname">Full path to the directory</param>
        /// <param name="win32FindData"><see cref="Win32FindData"/></param>
        internal QuickIODirectoryInfo( String fullname, Win32FindData win32FindData )
            : this( new QuickIOPathInfo( fullname ), win32FindData )
        {

        }
        /// <summary>
        /// Creates the folder information on the basis of the path and the handles
        /// </summary>
        /// <param name="pathInfo"><see cref="QuickIOPathInfo"/></param>
        /// <param name="win32FindData"><see cref="Win32FindData"/></param>
        internal QuickIODirectoryInfo( QuickIOPathInfo pathInfo, Win32FindData win32FindData ) :
            base( pathInfo, win32FindData )
        {

        }
        /// <summary>
        /// Creates instance of <see cref="QuickIOFileMetadata"/>
        /// </summary>
        /// <param name="uncResultPath">UNC Path of current file</param>
        /// <param name="win32FindData">Win32FindData of current file</param>
        internal QuickIOFileMetadata( string uncResultPath, Win32FindData win32FindData )
            : base( uncResultPath, win32FindData )
        {

        }
 /// <summary>
 /// Gets the creation time based on UTC
 /// </summary>
 /// <returns></returns>
 public static DateTime GetCreationTimeUtc(this Win32FindData source)
 {
     return(ConvertDateTime(source.ftCreationTime_dwHighDateTime, source.ftCreationTime_dwLowDateTime));
 }
 /// <summary>
 /// Returns type of entry
 /// </summary>
 public static QuickIOFileSystemEntryType GetFileSystemEntryType(this Win32FindData source)
 {
     return(IsDirectory(source) ? QuickIOFileSystemEntryType.Directory : QuickIOFileSystemEntryType.File);
 }
        /// <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;
        }
        /// <summary>
        /// Checks whether a directory supplied by PINvoke is relevant
        /// </summary>
        /// <param name="win32FindData"><see cref="Win32FindData"/></param>
        /// <returns>true if is relevant; otherwise false</returns>
        public static Boolean IsSystemDirectoryEntry(this Win32FindData win32FindData)
        {
            Contract.Requires(win32FindData != null);

            return(win32FindData.cFileName == "." || win32FindData.cFileName == "..");
        }