Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:3k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::DoCutFile(AnsiString sfilename,AnsiString dfilename)
- {
- int sfile,count;
- int rt;
- //打开文件
- sfile=FileOpen(sfilename,fmOpenRead);
- if(sfile==-1)return;
- count=1;
- do{
- rt=CopyOne(sfile,dfilename,count);
- count++;
- }while(rt==0);
- FileClose(sfile);
- Application->MessageBox("文件分割完毕!","提示",MB_OK);
- }
- //---------------------------------------------------------------------------
- int __fastcall TForm1::CopyOne(int sfile,AnsiString dfilename,int no)
- {
- char * MyBuff;
- int rt;
- AnsiString ass;
- int bn,ii,nn;
- MyBuff=new char[10010];
- if(MyBuff==NULL)
- {
- Application->MessageBox("系统内存不够!","提示",MB_OK);
- return -1;
- }
- ass="生成第 "+IntToStr(no)+" 个分割文件";
- Application->MessageBox(ass.c_str(),"提示",MB_OK);
- while(!TestDiskFree())
- {
- ass="磁盘空间不够!n要求空间为1,400,300字节!n继续吗?";
- bn=Application->MessageBox(ass.c_str(),"提示",MB_YESNO);
- if(bn!=IDYES)return -1;
- }
- bn=FileCreate(dfilename+"."+IntToStr(no));
- rt=0;
- for(ii=0;ii<140;ii++)
- {
- nn=FileRead(sfile,MyBuff,10000);
- FileWrite(bn,MyBuff,nn);
- if(nn!=10000)
- {
- rt=1;
- break;
- }
- }
- FileClose(bn);
- delete MyBuff;
- return rt;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TForm1::TestDiskFree(void)
- {
- __int64 ll;
- ll=DiskFree(0);
- if(ll<1403000L)return False;
- else return True;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- if(OpenDialog1->Execute())
- {
- Edit1->Text=OpenDialog1->FileName;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- int ll,ii;
- AnsiString ass;
- if(SaveDialog1->Execute())
- {
- Edit2->Text=SaveDialog1->FileName;
- ass=Edit2->Text;
- ll=ass.Length();
- for(ii=ll;ii>0;ii--)
- {
- if(ass.SubString(ii,1)==".")
- {
- ass=ass.SubString(1,ii-1);
- Edit2->Text=ass;
- break;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- DoCutFile(Edit1->Text,Edit2->Text);
- }
- //---------------------------------------------------------------------------