欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

C#实现一次分割多个文件

程序员文章站 2022-04-26 13:32:43
...
using System.IO;
using System.Windows.Forms;
 
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter ="All files (*.*)|*.*";
dlg.FilterIndex = 1;
dlg.RestoreDirectory = true;
dlg.Multiselect = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
    foreach (string filetosplit in dlg.FileNames)
    {
            string targetpath="D:";
            FileStream fsr = new FileStream(filetosplit, FileMode.Open, FileAccess.Read);
            long FileLength=fsr.Length;
            byte[] btArr = new byte[FileLength];
            fsr.Read(btArr, 0, (int)FileLength);
            fsr.Close();
            long PartLength=FileLength/3+FileLength%3;
            int nCount=(int)Math.Ceiling((double)FileLength/PartLength);
            string strFileName=Path.GetFileName(filetosplit);
            long byteCount=0;
            for(int i=1;i