void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMemoryStream * TranFile =new TMemoryStream();
int FileHandle; // 文件名柄变量
int FileLength; //源文件大小变量
int num; //源文件被分割后的文件数目
int iBytesRead;//
char *pszBuffer;
int buf; // 文件缓冲区变量
int buf1;//文件缓冲区变量
buf=1024*20;//每分大小
buf1=buf*1024l;
if(OpenDialog1->Execute())
{
AnsiString fn=OpenDialog1->FileName;
//AnsiString name=ExtractFileName(fn).SubString(1,ExtractFileName(fn).Length()-ExtractFileExt(fn).Length());
FileHandle=FileOpen(fn, fmOpenRead);
FileLength=FileSeek(FileHandle,0,2);
num=FileLength/buf1+1;
Caption="分割成"+IntToStr(num)+"个文件";
if (num==1)//判断欲分割的文件是否小于要分割的字节大小
{
ShowMessage("文件小于要分割的大小,不用分割");
return;
}
pszBuffer = new char [buf1]; //设置读写文件缓冲区
int Handle=0;
for(int i=1;i<=num;i++)
{
FileSeek(FileHandle,,)
FileRead(FileHandle, pszBuffer,buf1);
Handle=FileCreate((ChangeFileExt(ExtractFileName(OpenDialog1->FileName),"."+IntToStr(i))));
FileWrite(Handle,pszBuffer,buf1);
if(i==num-1)
buf1=FileLength-buf1*i;
FileClose(Handle);
}
FileClose(FileHandle);
/*int i=1;
pszBuffer = new char [buf1]; //设置读写文件缓冲区
int temp=buf1;
for (i=1;i<=num;i++)
{
if (i==num)
pszBuffer = new char [FileLength-buf1*(num-1)];
if (i==num)
temp=FileLength-buf1*(num-1);
FileHandle=FileOpen(Edit1->Text,fmOpenRead);//打开文件名柄
FileSeek(FileHandle,buf1*(i-1),0);
if (FileRead(FileHandle, pszBuffer,temp)!=temp)
ShowMessage("Read error!");
FileClose(FileHandle);
int Handle=FileCreate((ChangeFileExt(ExtractFileName(OpenDialog1->FileName),"."+IntToStr(i))));
if (FileWrite(Handle,pszBuffer,temp)!=temp)
ShowMessage("Write error!");
FileClose(Handle);
} */
}
try
{
NMStrm1->Host=Edit1->Text;
NMStrm1->PostIt(TranFile);
}
catch(...)
{
ShowMessage("发送不成功!");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMStrmServ1MSG(TComponent *Sender,
const AnsiString sFrom, TStream *strm)
{
//if(SaveDialog1->Execute())
//{
// TFileStream * SaveFile=new TFileStream(SaveDialog1->FileName,fmCreate);
// SaveFile->CopyFrom(strm,strm->Size);
//}
}
//---------------------------------------------------------------------------
--------------------next---------------------
阅读(1023) | 评论(0) | 转发(0) |