There are several cases of you question, but none of them is language relevant.
Following are something to concern
- What is the file system of source/destination file?
- Do you want to keep original source file?
- Are they lie on the same drive?
In c#, you almost do not have a method could be faster than File.Copy
which invokes CopyFile
of WINAPI
internally. Because of the percentage is fifty, however, following code might not be faster. It copies whole file and then set the length of the destination file
var info=new FileInfo(fileName);
var percentSplit=info.Length*50/100; // extract 50% of file
File.Copy(info.FullName, splitName);
using(var outStream=File.OpenWrite(splitName))
outStream.SetLength(percentSplit);
Further, if
- you don't keep original source after file splitted
- destination drive is the same as source
- your are not using a crypto/compression enabled file system
then, the best thing you can do, is don't copy files at all.
For example, if your source file lies on FAT
or FAT32
file system, what you can do is
- create new dir entry(entries) for newly splitted parts of file
- let the entry(entries) point(s) to the cluster of target part(s)
- set correct file size for each entry
- check for cross-link and avoid that
If your file system was NTFS
, you might need to spend a long time to study the spec.
Good luck!