/// <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) { base.SetFindData( win32FindData ); Bytes = win32FindData.CalculateBytes( ); }
/// <summary> /// Determines the statistics of the given directory. This includes the number of files, folders and the total size in bytes. /// </summary> /// <param name="path">Path to the directory to generate the statistics.</param> /// <param name="enumerateOptions">Options <see cref="QuickIOEnumerateOptions"/></param> /// <returns>Provides the statistics of the directory</returns> /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception> public static QuickIOFolderStatisticResult GetDirectoryStatistics( String path, QuickIOEnumerateOptions enumerateOptions = QuickIOEnumerateOptions.None ) { UInt64 fileCount = 0; UInt64 folderCount = 0; UInt64 totalSize = 0; // Match for start of search var currentPath = QuickIOPath.Combine( path, QuickIOPatternConstants.All ); // Find First file var win32FindData = new Win32FindData( ); int win32Error; using ( var fileHandle = FindFirstSafeFileHandle( currentPath, win32FindData, out win32Error ) ) { // Take care of invalid handles if ( fileHandle.IsInvalid ) { if ( EnumerationHandleInvalidFileHandle( currentPath, enumerateOptions, win32Error ) ) { return null; } } // Treffer auswerten do { // Ignore . and .. directories if ( InternalRawDataHelpers.IsSystemDirectoryEntry( win32FindData ) ) { continue; } // Create hit for current search result var resultPath = QuickIOPath.Combine( path, win32FindData.cFileName ); // if it's a file, add to the collection if ( !InternalHelpers.ContainsFileAttribute( win32FindData.dwFileAttributes, FileAttributes.Directory ) ) { fileCount++; totalSize += win32FindData.CalculateBytes( ); win32FindData.CalculateBytes( ); } else { folderCount++; var result = GetDirectoryStatistics( resultPath, enumerateOptions ); { folderCount += result.FolderCount; fileCount += result.FileCount; totalSize += result.TotalBytes; } } // Create new FindData object for next result win32FindData = new Win32FindData( ); } // Search for next entry while ( Win32SafeNativeMethods.FindNextFile( fileHandle, win32FindData ) ); } // Return result; return new QuickIOFolderStatisticResult( folderCount, fileCount, totalSize ); }
/// <summary> /// Calculates the size of the file from the handle /// </summary> /// <param name="win32FindData"></param> private void CalculateSize( Win32FindData win32FindData ) { this.Bytes = win32FindData.CalculateBytes( ); }