/// <summary> /// Copy directory or file, take full path of source and dest as parameter. /// </summary> public static void CopyFile(string source, string dest, FileCancelDelegate cancel) { using (FileStreamEx srcStream = FileEx.OpenRead(source)) { byte[] buffer = new byte[Math.Min(1024 * 1024 * 32, srcStream.Length)]; //32MB int readCount; ushort completePercent = 0; long completeCount = 0; using (FileStreamEx destStream = FileEx.Create(dest)) { while ((readCount = srcStream.Read(buffer, 0, buffer.Length)) > 0 && !IsCancelTriggered(cancel, completePercent)) { completeCount += readCount; destStream.Write(buffer, 0, readCount); completePercent = srcStream.Length == 0 ? (ushort)100 : (ushort)((float)completeCount / (float)srcStream.Length * 100.0); } destStream.Flush(); destStream.Close(); } srcStream.Close(); } }