bool CipodtxtDlg::split(void) { CString cs, out, tmp; CFile cif, cof; CFileException ex; char buffer[4096] = { 0 }; char *p; int nread, n;
GetDlgItemText(IDC_EDIT1, cs);
if(!cif.Open(cs, CFile::modeRead, &ex)) { return false; } tmp = cs.Mid(0, cs.ReverseFind('.'));
int nfile = (int)(cif.GetLength() / 4096) + 1; for(int i=0; nread=cif.Read(buffer, 4096), nread>0;++i) { out.Format(_TEXT("%s_%.8d.txt"), (LPCTSTR)tmp, i); if(cof.Open(out, CFile::modeCreate|CFile::modeWrite, &ex)) { p = buffer+4095; n = 0;
//如果最后一个字节不是完整汉字,本文件放弃,由下一个文件输出。 while(!isascii(*p) && p!=buffer) { p--; n++; } if(n%2==1) { nread--; cif.Seek(-1, CFile::current); }
cof.Write(buffer, nread); cof.Close(); memset(buffer, 0, 4096); } m_pc.SetPos(i*100/nfile); }
cif.Close(); m_pc.SetPos(100); return true; }
|