// split_1.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "io.h"
#include "flags.h"
//#include "maths.h"
#define B_LEN 1400000
//#include <sys/types.h>
//#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
char buff[B_LEN];char f_name[25],cur_name[25];void makename(int );int main(int argc, char* argv[])
{
int mor_buf,ncount;
cin>>f_name;
int tmp=_open(f_name,_O_BINARY|_O_RDONLY);
long file_length=_filelength(tmp);
if(file_length>B_LEN)
mor_buf =1;
else mor_buf =0;
_close(tmp);
ncount =int (file_length/B_LEN)+1;int i;
//f_name="f:\\1!s.mp3";
FILE *src=fopen(f_name,"r+b");
if (src==NULL)
{cout<<"err on opening "<<f_name<<endl;
return 0;
}
//f_name[10]='\0';
FILE *rcd=fopen("record.txt","a+t");
fputs("source:",rcd);
fputs(f_name,rcd);
fputc('\n',rcd);
for(i=1;i<ncount;i++)
{//fread(buff,B_LEN,1,src+(i-1)*B_LEN);
for(int j=0;j<1400000;j++){
fseek(src,(i-1)*B_LEN+j,0);
buff[j]=fgetc(src);}
makename(i);
FILE *cur_file=fopen(cur_name,"w+b");
if(cur_file==NULL)
cout<<"err on opening "<<cur_name<<endl;
fwrite(buff,B_LEN,1,cur_file);
fclose(cur_file);
fputs(cur_name,rcd);
fputc('\n',rcd);
}
cout<<i<<endl;
int xtra_count;
xtra_count=int (filelength) % B_LEN;
//fread(buff,xtra_count,1,src+(i-1)*B_LEN);
for(int u=0;u<xtra_count;u++){
fseek(src,(i-1)*B_LEN+u,0);
buff[u]=fgetc(src);}
/*int u;
u=0;fseek(src,0,(i-1)*B_LEN+u);
buff[u]=fgetc(src);do{u++;
fseek(src,0,(i-1)*B_LEN+u);
buff[u]=fgetc(src);}while(buff[u]!='\0');*/makename(i);
FILE *cur_file=fopen(cur_name,"w+b");
fwrite(buff,u,1,cur_file);
fclose(cur_file);
fputs(cur_name,rcd);
fputc('\n',rcd);
fclose(rcd);
return 0;
}
void makename(int i)
{int k=4;
for(int y=0;y<3;y++)cur_name[y]=f_name[y];
cur_name[3]=i+48;
do{cur_name[k]=f_name[k-1];
k++;
}while(k<25);
}\\拆分程序
//#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "io.h"
#include "flags.h"
//#include "maths.h"
#define B_LEN 1400000
//#include <sys/types.h>
//#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
char buff[B_LEN];char f_name[25],cur_name[25];void makename(int );int main(int argc, char* argv[])
{
int mor_buf,ncount;
cin>>f_name;
int tmp=_open(f_name,_O_BINARY|_O_RDONLY);
long file_length=_filelength(tmp);
if(file_length>B_LEN)
mor_buf =1;
else mor_buf =0;
_close(tmp);
ncount =int (file_length/B_LEN)+1;int i;
//f_name="f:\\1!s.mp3";
FILE *src=fopen(f_name,"r+b");
if (src==NULL)
{cout<<"err on opening "<<f_name<<endl;
return 0;
}
//f_name[10]='\0';
FILE *rcd=fopen("record.txt","a+t");
fputs("source:",rcd);
fputs(f_name,rcd);
fputc('\n',rcd);
for(i=1;i<ncount;i++)
{//fread(buff,B_LEN,1,src+(i-1)*B_LEN);
for(int j=0;j<1400000;j++){
fseek(src,(i-1)*B_LEN+j,0);
buff[j]=fgetc(src);}
makename(i);
FILE *cur_file=fopen(cur_name,"w+b");
if(cur_file==NULL)
cout<<"err on opening "<<cur_name<<endl;
fwrite(buff,B_LEN,1,cur_file);
fclose(cur_file);
fputs(cur_name,rcd);
fputc('\n',rcd);
}
cout<<i<<endl;
int xtra_count;
xtra_count=int (filelength) % B_LEN;
//fread(buff,xtra_count,1,src+(i-1)*B_LEN);
for(int u=0;u<xtra_count;u++){
fseek(src,(i-1)*B_LEN+u,0);
buff[u]=fgetc(src);}
/*int u;
u=0;fseek(src,0,(i-1)*B_LEN+u);
buff[u]=fgetc(src);do{u++;
fseek(src,0,(i-1)*B_LEN+u);
buff[u]=fgetc(src);}while(buff[u]!='\0');*/makename(i);
FILE *cur_file=fopen(cur_name,"w+b");
fwrite(buff,u,1,cur_file);
fclose(cur_file);
fputs(cur_name,rcd);
fputc('\n',rcd);
fclose(rcd);
return 0;
}
void makename(int i)
{int k=4;
for(int y=0;y<3;y++)cur_name[y]=f_name[y];
cur_name[3]=i+48;
do{cur_name[k]=f_name[k-1];
k++;
}while(k<25);
}\\拆分程序
//#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "io.h"
//#include "flags.h"
//#include "maths.h"
#define B_LEN 1400000
//#include <sys/types.h>
//#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
char buff[B_LEN];char f_name[25],cur_name[25];void makename1(int);int main(int argc, char* argv[])
{cout<<"plz input the lastest file name !"<<endl;
cin>>cur_name;
cout<<"plz input the source file name";
cin>>f_name;
FILE *src=fopen(f_name,"a+b");
if (src==NULL)
{cout<<"error in opening source file :"<<f_name<<endl;
return 0;
}int count =cur_name[3]-48;
for(int i=1;i<=count;i++)
{makename1(i);
int tmp=_open(cur_name,_O_BINARY|_O_RDONLY);
long file_length=_filelength(tmp);
/*if(file_length>B_LEN)
mor_buf =1;
else mor_buf =0;*/
_close(tmp);
//ncount =int (file_length/B_LEN)+1;
FILE *cur_file=fopen(cur_name,"r+b");
fread(buff,file_length,1,cur_file);
fwrite(buff,file_length,1,src);
fclose(cur_file);
}
fclose(src);
return 0;
}void makename1(int i)
{//int k=4;
//for(int y=0;y<3;y++)cur_name[y]=f_name[y];
cur_name[3]=i+48;
/*do{cur_name[k]=f_name[k-1];
k++;
}while(k<25);
*/
}\\组装程序
\\他们都只能在硬盘的跟目录下使用
\\还有点小问题
\\在www.vchelp.net上也有文件分割器的vc程序
\\我用c变得,用了几个microsoft独有的函数
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;
}//选择待分割或合并的源文件
void CFileSpltDlg::OnBrowse()
{
//set filter for split source
static char BASED_CODE szSplitFilter[] = _T("待分割文件(*.*)|*.*||");
//set filter for target source
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); //set source path
if (dlg.DoModal() == IDOK) {
m_path = dlg.GetPathName();
m_filename = dlg.GetFileName();
UpdateData(FALSE);
}
}
我晕@!#@!¥#%%~!#@%^¥&%^&