谢谢,高分哦~

解决方案 »

  1.   

    void CCut::OnKaishi() 
    {
        hebingneirong="copy ";//初始化合并文件内容
    // TODO: Add your control notification handler code here
    //得到正确的存放位置
    if (m_savepath.Right (1)!='\\')
    m_savepath=m_savepath + '\\';
    GetDlgItem(IDC_PER)->GetWindowText(m_per);//m_per关联设置的分割后每份文件的大小
    long per;//得到每份文件得大小,单位是K字节
    per=atoi(m_per);
    per=per*1024;//单位变为字节
    if(per>=total)
    {
    MessageBox("分割后的文件大于或等于分割前的!重新设置。","错误,重新设置",MB_ICONERROR);
    return;
    }
    CFile fsource,ftarget;
    CStdioFile hebing;
    if(!fsource.Open (m_sorcepath,CFile::modeRead))
    {
    MessageBox("打开原文件时失败!","打开文件失败",MB_ICONERROR);
    return;
    }
    int index,index1=0;//index为生成文件得个数,index1为生成每个文件时要循环得次数
    int houzhui=0;//生成文件得后缀名
    ////////////////
    //计算大循环需要的次数
    if(total%per==0)
      index=total/per;
    else index=total/per+1;
    /////////////////////////
    BYTE buffer[4096];//分配4k大小的缓冲区
    ///////////////////////////////////////////////////
    //主循环体
    CString m_source;//临时设置的生成文件名字的存储地方
        char s[20];
    int ncount;
    long shengyu;//每次小循环不足4k的部分
    shengyu=per%4096;
    CString hebingwenjian=m_savepath+filename+".bat";
    if(!hebing.Open (hebingwenjian,CStdioFile::modeCreate|CFile::modeWrite))
    {
        MessageBox("创建合并执行程序时失败!","写文件失败",MB_ICONERROR);
    hebing.Close ();
    return;
    }

    while(index!=0)
    {
    //计算生成每个小文件需要的循环次数,这个次数比实际的要少一次
        index1=per/4096;
        ///////////////////////////////
    itoa(houzhui,s,10);
    m_source=m_savepath+filename;
    m_source+=s;
    houzhui++;
    if(!ftarget.Open (m_source,CFile::modeCreate|CFile::modeWrite))
    {
    MessageBox("写文件时失败!","写文件失败",MB_ICONERROR);
    ftarget.Close ();
    return;
    }
    while(index1!=0)
    {
    ncount=fsource.Read (buffer,4096);
    ftarget.Write (buffer,ncount);
    index1--;
    }

    if(ncount!=0)
    {
    ncount=fsource.Read (buffer,shengyu);
    ftarget.Write (buffer,ncount);
    }
    if ((index-1)!=0)
    hebingneirong=hebingneirong + m_source + "/b+";
    else hebingneirong=hebingneirong + m_source + "/b";
    index--;
    ftarget.Close ();
    }
    fsource.Close ();
        UpdateData(TRUE);
    hebingneirong=hebingneirong+ " " + m_savepath + filename;
    hebing.WriteString (hebingneirong);
    hebing.Close ();
    MessageBox("恭喜,分割成功!","恭喜",MB_ICONINFORMATION);
    }