您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 分割合并文件
  所属分类: C++
  开发工具:
  文件大小: 33kb
  下载次数: 0
  上传时间: 2012-01-15
  提 供 者: wjh627******
 详细说明: // 文件合并涵数 int CFileSpltDlg::MergeMe() { CWaitCursor wait; // constructing these file objects CFile destFile; // we'll use a CFileException object to get error information CFileException ex; BYTE buffer[140000]; DWORD dwRead; UINT nCount = 140000; UINT newlen = 1400000; char buff [20]; long l = 1; CString name; CString pref; CString newpath; UpdateData(TRUE); //open file for read if (!m_path.IsEmpty()) { if (!m_SourceFile.Open(m_path, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); m_edit.SetFocus(); m_edit.SetSel(0, -1); return 1; } //construct new name m_filename = m_path.Right((m_path.GetLength() - m_path.ReverseFind('\\')) - 1); //close file m_SourceFile.Close(); } //constuct a new path name newpath = m_path.Left(m_path.GetLength() - m_filename.GetLength()); if (!m_targetpath.IsEmpty()) { //some silly check, that could be chnged if (!m_filename.IsEmpty() && m_filename.Left(2) != _T("1_")) { ::AfxMessageBox(_T("待合并的源文件名不对..."), MB_ICONERROR); return 1; } else if(m_filename.IsEmpty()) { MessageBox(_T("请选择待合并的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } //constuct an original file name m_filename = m_filename.Right(m_filename.GetLength() - 2); //判断选择目录未尾是否已有"\"符 if(m_targetpath.Right(1)=='\\') m_path = m_targetpath + m_filename; else m_path = m_targetpath + _T("\\") + m_filename; //create target file if (!destFile.Open(m_path, CFile::modeWrite | CFile::shareExclusive | CFile::typeBinary | CFile::modeCreate, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); return 0; } } else if(m_path.IsEmpty()) {//souce is not there MessageBox(_T("请选择待合并的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } if (m_targetpath.IsEmpty()) {//target is not there MessageBox(_T("请选择合并后要保存到的目标文件夹."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } //do merge do { //constuct a new name by dynamicly incrementing prefix pref = _ltoa(l, buff, 10); pref += _T("_"); //open file with new name if (!m_SourceFile.Open(newpath + pref + m_filename, CFile::modeRead | CFile::shareExclusive | CFile::typeBinary, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); destFile.Close(); m_path = _T(""); m_filename = _T(""); // pProgress.SetPos(0); newpath = _T(""); // m_parts = _T(""); UpdateData(FALSE); //return OK because this f_n is aborting the loop if name is not found return 0; } else //constuct a new name name = _T(newpath + pref + m_filename); do {//write into file while it size < than 1.4 MB dwRead = m_SourceFile.Read(buffer, nCount); destFile.Write(buffer, dwRead); } //while we can read from source file while (dwRead > 0); m_SourceFile.Close(); // Set the range to be 0 to 500. pProgress.SetRange(0, 500); // Set the position for (int i = 0; i < 500; i++) pProgress.SetPos(i); m_parts = _ltoa(l, buff, 10); m_parts += _T("个文件已合并"); UpdateData(FALSE); l++; UpdateWindow(); } while (l < 500);//little bit dirty solution, but you can always improve it!... return 0; } //文件分割涵数 int CFileSpltDlg::SplitMe() { CWaitCursor wait; // constructing these file objects CFile destFile; // we'll use a CFileException object to get error information CFileException ex; DWORD dwRead; UINT newlen; char buff [20]; char b [20]; long l = 1; CString name; UINT len = 0; // CGradientProgressCtrl *pProgress = (CProgressCtrl*) GetDlgItem(IDC_PROGRESS); UpdateData(TRUE); //获取文件分割后的大小,定义相对应变量数值 newlen=GetSplitFileSize(); UINT nCount = newlen/10; BYTE buffer[140000]; //open file for read //m_path contain the file path if (!m_path.IsEmpty()) { if (!m_SourceFile.Open(m_path, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); m_edit.SetFocus(); m_edit.SetSel(0, -1); return 1; } //get file length len = m_SourceFile.GetLength(); } //too lazy to put all "hard coded" strings in string table else { MessageBox(_T("请选择待分割的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } if (m_targetpath.IsEmpty()) { MessageBox(_T("请选择分割后保存到的目标文件夹."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } //quick and dirty check for file size if (len < newlen) { CString length = _itoa(len, b, 10); MessageBox(_T("文件长度为 " + length + " 字节,不够指定的分割大小, 没有必要再进行分割."), _T("文件分割器"), MB_ICONEXCLAMATION); m_SourceFile.Close(); m_path = _T(""); m_filename = _T(""); UpdateData(FALSE); return 1; } //do split do { //constuct a new name dynamicly changing prefix name = _ltoa(l, buff, 10); name += _T("_"); CString newpath; //判断选择目录未尾是否已有"\"符 if(m_targetpath.Right(1)=='\\') newpath = m_targetpath; else newpath = m_targetpath + _T("\\"); if (!destFile.Open(newpath + name + m_SourceFile.GetFileName(), CFile::modeWrite | CFile::shareExclusive | CFile::typeBinary | CFile::modeCreate, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); m_SourceFile.Close(); return 1; } do { dwRead = m_SourceFile.Read(buffer, nCount); destFile.Write(buffer, dwRead); }//while size is less than 1.4 MB while (dwRead > 0 && destFile.GetLength() < newlen); destFile.Close(); // Set the range pProgress.SetRange(0, len /newlen*10); // Set the position pProgress.SetPos(l); m_parts = _ltoa(l , buff, 10); m_parts += _T("个文件生成"); UpdateData(FALSE); l++; UpdateWindow(); } while (dwRead > 0); // close source m_SourceFile.Close(); m_path = _T(""); m_filename = _T(""); // pProgress.SetPos(0); // m_parts = _T(""); UpdateData(FALSE); return 0; } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 分割文件 合并文件
 输入关键字,在本站1000多万海量源码库中尽情搜索: