Created
May 24, 2014 00:12
-
-
Save daveamato/acf2bebf922bef6346e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> Fast file move with big buffers | |
/// </summary> | |
/// <param name="source">Source file path</param> | |
/// <param name="destination">Destination file path</param> | |
static void FMove (string source, string destination) | |
{ | |
int array_length = (int) Math.Pow (2, 20); | |
byte[] dataArray = new byte[array_length]; | |
FileStream fsread = new FileStream (source, FileMode.Open, FileAccess.Read, FileShare.None, array_length * 2); | |
BinaryReader bwread = new BinaryReader (fsread); | |
FileStream fswrite = new FileStream (destination, FileMode.Create, FileAccess.Write, FileShare.None, array_length * 2); | |
BinaryWriter bwwrite = new BinaryWriter (fswrite); | |
for (; ; ) | |
{ | |
int read = bwread.Read (dataArray, 0, array_length); | |
if (0 == read) | |
break; | |
bwwrite.Write (dataArray, 0, read); | |
} | |
bwwrite.Close (); | |
fswrite.Close (); | |
bwread.Close (); | |
fsread.Close (); | |
File.Delete (source); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment