以下是几个主要的函数,具体的实现请参考源代码:
long CFileSpltDlg::GetSplitFileSize() //获取用户选择文件分割后的大小
{
char buf[100];
m_FileSize.GetWindowText(buf,100);
for(int i=0; i<(int)strlen(buf); i++)
{
if(!::isdigit(buf[i]))
{
MessageBox("请输入数字!","文件分割",MB_ICONEXCLAMATION);
return 0;
}
}
return atoi(buf)*1000000;
}
int CFileSpltDlg::MergeMe() // 文件合并涵数
{
CWaitCursor wait;
CFile destFile;
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);
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;
}
m_filename = m_path.Right((m_path.GetLength() - m_path.ReverseFind('\\')) -
1);
m_SourceFile.Close();
}
newpath = m_path.Left(m_path.GetLength() - m_filename.GetLength());
if (!m_targetpath.IsEmpty())
{
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;
}
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;
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())
{
MessageBox(_T("请选择待合并的源文件."), _T("文件分割器"),
MB_ICONEXCLAMATION);
return 1;
}
if (m_targetpath.IsEmpty())
{
//target is not there
MessageBox(_T("请选择合并后要保存到的目标文件夹."), _T("文件分割器"),
MB_ICONEXCLAMATION);
return 1;
}
do
{
pref = _ltoa(l, buff, 10);
pref += _T("_");
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("");
newpath = _T("");
UpdateData(FALSE);
return 0;
}
else
name = _T(newpath + pref + m_filename);
do
{
dwRead = m_SourceFile.Read(buffer, nCount);
destFile.Write(buffer, dwRead);
}
while (dwRead > 0);
m_SourceFile.Close() ;
pProgress.SetRange(0, 500);
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) ;
return 0;
}
int CFileSpltDlg::SplitMe() //文件分割涵数
{
CWaitCursor wait;
CFile destFile;
CFileException ex;
DWORD dwRead;
UINT newlen;
char buff [20];
char b [20];
long l = 1;
CString name;
UINT len = 0;
UpdateData(TRUE);
newlen=GetSplitFileSize(); //获取文件分割后的大小,定义相对应变量数值
UINT nCount = newlen/10;
BYTE buffer[140000];
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;
}
len = m_SourceFile.GetLength();
}
else
{
MessageBox(_T("请选择待分割的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION);
return 1;
}
if (m_targetpath.IsEmpty())
{
MessageBox(_T("请选择分割后保存到的目标文件夹."), _T("文件分割器"),
MB_ICONEXCLAMATION);
return 1;
}
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 {
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 (dwRead > 0 && destFile.GetLength() < newlen);
destFile.Close();
pProgress.SetRange(0, len /newlen*10);
pProgress.SetPos(l);
m_parts = _ltoa(l , buff, 10);
m_parts += _T("个文件生成");
UpdateData(FALSE);
l++;
UpdateWindow();
}while (dwRead > 0);
m_SourceFile.Close();
m_path = _T("");
m_filename = _T("");
UpdateData(FALSE);
return 0;
}
目录浏览:
void CFileSpltDlg::OnBrowse()
{
static char BASED_CODE szSplitFilter[] = _T("待分割文件(*.*)|*.*||");
static char BASED_CODE szMergeFilter[] = _T("待合并文件(1_*.*)|1_*.*||");
CString filter;
if (!m_split)
filter = szMergeFilter;
else
filter = szSplitFilter;
CFileDialog dlg(TRUE,
NULL,
NULL,
OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT |
OFN_FILEMUSTEXIST,
filter,
0);
if (dlg.DoModal() == IDOK)
{
m_path = dlg.GetPathName();
m_filename = dlg.GetFileName();
UpdateData(FALSE);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
文件分割源代码,可以对任意大小的文件进行分割
共27个文件
h:5个
cpp:4个
bmp:2个
3星 · 超过75%的资源 需积分: 10 20 下载量 79 浏览量
2008-09-15
08:38:38
上传
评论
收藏 408KB RAR 举报
温馨提示
文件分割的源代码,可以对任意大小的文件进行分割,很好的参考材料
资源推荐
资源详情
资源评论
收起资源包目录
vc61567688244.rar (27个子文件)
cvery.comvc61567688244
FileSpltDlg.h 2KB
FileSplt.clw 2KB
res
FileSplt.ico 1KB
xptheme.bin 653B
Button1.bmp 5KB
1.cur 2KB
Thumbs.db 5KB
FileSplt.rc2 400B
ButtonsWin3000.bmp 18KB
1.ico 4KB
下载说明.htm 5KB
FileSplt.rc 6KB
~VC1A4.tmp 2KB
Link.h 1KB
FileSplt.cpp 2KB
FileSplt.dsw 539B
FileSpltDlg.cpp 11KB
StdAfx.cpp 210B
resource.h 1KB
FileSplt.aps 64KB
FileSplt.exe 2.08MB
StdAfx.h 1KB
~VC1CE.tmp 65KB
FileSplt.h 1KB
相关说明.txt 6KB
Link.cpp 3KB
FileSplt.dsp 5KB
共 27 条
- 1
资源评论
- AiXiXi2012-06-28很一般的资源,只是基本实现了功能,程序不够完善。
chafee
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功