急用文件合并,分割代码

templez 2004-07-29 01:34:50
合并:
4个不同格式的文件,合并成一个文件

分割:
读这个文件,分割成4个文件

以前的例子,看不懂,比如说“利用C++ Builder设计实现文件切割机”。
请提供详细的源代码,谢谢。
...全文
107 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
constantine 2004-07-29
  • 打赏
  • 举报
回复
zaqizaba(渣渣)你去收了
zaqizaba 2004-07-29
  • 打赏
  • 举报
回复
lihui@uppchina.com
zaqizaba@hotmail.com
谢谢大家
constantine 2004-07-29
  • 打赏
  • 举报
回复
TShellTreeView等第三方控件时Example里面那个,自己装一下,你可以不用,
要整份代码可以跟我联系
constantine.student@sina.com
constantine 2004-07-29
  • 打赏
  • 举报
回复

Unit2.h
//////
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ShellCtrls.h"
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TPanel *Panel1;
TShellTreeView *ShellTreeView1;
TCheckBox *CheckBox1;
TButton *Button1;
TButton *Button2;
TEdit *Edit1;
TLabel *Label2;
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
constantine 2004-07-29
  • 打赏
  • 举报
回复
Unit2.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ShellCtrls"
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm2::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
if(CheckBox1->Checked==true)
Form1->Path="C:\\temp\\";
else
Form1->Path=ShellTreeView1->Path+"\\";
Hide();
Form1->Caption=" 切割机 ---> "+Form1->Path;
}
//---------------------------------------------------------------------------

constantine 2004-07-29
  • 打赏
  • 举报
回复
Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <FileCtrl.hpp>
#include "ShellCtrls.h"
#include <ExtCtrls.hpp>
#include <Menus.hpp>
#include <Dialogs.hpp>
#include "CSPIN.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TPanel *Panel2;
TFileListBox *FileListBox1;
TStatusBar *Bar;
TPanel *Panel4;
TGroupBox *GroupBox2;
TGroupBox *JD;
TProgressBar *ProgressBar1;
TMainMenu *MainMenu1;
TMenuItem *N1;
TMenuItem *N2;
TMenuItem *N3;
TMenuItem *N4;
TScrollBox *ScrollBox1;
TListBox *ListBox1;
TOpenDialog *OpenDialog1;
TShellTreeView *ShellTreeView1;
TMenuItem *N5;
TGroupBox *GroupBox1;
TRadioButton *Button2;
TRadioButton *Button1;
TRadioButton *Button3;
TLabel *Label1;
TEdit *Edit1;
void __fastcall FileListBox1Click(TObject *Sender);
void __fastcall ShellTreeView1DblClick(TObject *Sender);
void __fastcall N4Click(TObject *Sender);
void __fastcall N3Click(TObject *Sender);
void __fastcall N1Click(TObject *Sender);
void __fastcall N2Click(TObject *Sender);
void __fastcall FileListBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y);
void __fastcall ListBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y);
void __fastcall N5Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall Edit1KeyPress(TObject *Sender, char &Key);
void __fastcall Edit1Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
private: // User declarations
int FileHandle; // 文件名柄变量
int FileLength; //源文件大小变量
int num; ///源文件被分割后的文件数目
int iBytesRead;
char *pszBuffer;
int buf,buf1; // 文件缓冲区变量

public: // User declarations
__fastcall TForm1(TComponent* Owner);
AnsiString Path;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
constantine 2004-07-29
  • 打赏
  • 举报
回复
给你帖出来,

Unit1.cpp
///////////////
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ShellCtrls"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString FileName;
bool kit=false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FileListBox1Click(TObject *Sender)
{
JD->Caption="进度";
ProgressBar1->Position=0;
if(kit==false)
{
FileName=ExtractFileName(FileListBox1->FileName);
Bar->Panels->Items[0]->Text=FileListBox1->FileName;
}
if(Button1->Checked==true)
buf=1000;
else if(Button2->Checked==true)
buf=1400;
else {
if(Edit1->Text<1)
Edit1->Text=1;
buf=StrToInt(Edit1->Text);
} //k
buf1=buf*1024l; //字节
FileHandle=FileOpen(Bar->Panels->Items[0]->Text, fmOpenRead);
FileLength=FileSeek(FileHandle,0,2);
num=FileLength/buf1+1;
Bar->Panels->Items[1]->Text="分割成"+IntToStr(num)+"个文件";
FileClose(FileHandle);
ListBox1->Items->Clear();
ListBox1->Items->Add(ChangeFileExt(Path+FileName,".bat"));
for (int i=1;i<=num;i++)
{
ListBox1->Items->Add(ChangeFileExt(Path+FileName,"."+IntToStr(i)));
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ShellTreeView1DblClick(TObject *Sender)
{
FileListBox1->Directory=ShellTreeView1->Path;
Bar->Panels->Items[0]->Text=ShellTreeView1->Path;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N4Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)
{
ShellAbout(Application->Handle,"constantine文件切割机(V1.01)","版权所有 (C) constantine 工作窒",NULL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N1Click(TObject *Sender)
{
if(OpenDialog1->Execute())
FileName=ExtractFileName(OpenDialog1->FileName);
Bar->Panels->Items[0]->Text=OpenDialog1->FileName;
kit=true;
FileListBox1Click(Sender);
kit=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)
{
if (FileLength<=buf1)// 判断欲分割的文件是否小于要分割的字节大小
{
ShowMessage("文件小于要分割的大小,不用分割");
return;
}
ForceDirectories(Path);
ProgressBar1->Max=num;//初始化进度条
ProgressBar1->Position=0;
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(Bar->Panels->Items[0]->Text,fmOpenRead); //打开文件名柄
FileSeek(FileHandle,buf1*(i-1),0);
if (FileRead(FileHandle, pszBuffer,temp)!=temp)
{
ShowMessage("Read error!");
break;
}
FileClose(FileHandle);
ProgressBar1->Position=i;
//JD->Caption="已进行:"+IntToStr(ProgressBar1->Position*100/num)+"%";
int Handle=FileCreate((ChangeFileExt(Path+FileName,"."+IntToStr(i))));
if (FileWrite(Handle,pszBuffer,temp)!=temp)
{
ShowMessage("Write error!");
break;
}
FileClose(Handle);
}
ProgressBar1->Position=i;
JD->Caption="完成分割";
//生成合并文件时的自动批处理文件代码
AnsiString name="copy/b ";
for (int i=1;i<=num;i++)
{
AnsiString shortname=ChangeFileExt(Path + FileName,"."+IntToStr(i));
if(i==1)
name=name+ExtractFileName(shortname);
else
name=name+"+"+ExtractFileName(shortname);
}
name=name+" "+FileName+"\ncls\nexit";
char *p;
FILE *fp;
if((fp=fopen((ChangeFileExt(Path+FileName,".bat")).c_str(),"w"))!=NULL)
fprintf(fp,"%s",name.c_str());
fclose(fp);
ShowMessage("分割成功,请到 "+Path+" 查看!");
ProgressBar1->Position=0;
ShellExecute(Handle,"Open",Path.c_str(),NULL,NULL,SW_SHOW);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileListBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
FileListBox1->Hint=ExtractFileName(FileListBox1->FileName);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBox1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
ListBox1->Hint=ListBox1->Items->Text;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N5Click(TObject *Sender)
{
Form2->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1->Text=1400;
FileListBox1->Directory=ShellTreeView1->Path;
Path="C:\\temp\\";
Form1->Caption=" 切割机 ---> "+Path;
Bar->Panels->Items[0]->Text="欢迎使用constantine文件切割机";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
AnsiString InputKey = Key;
int nInputKey=Key;
bool flag;
flag=false;
AnsiString ValidKey = AnsiString("0123456789");
if (ValidKey.Pos(InputKey) != 0)
flag=true;
if ((nInputKey!=8 && !flag))
Key=0;

Edit1Click(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit1Click(TObject *Sender)
{
if(Button1->Checked==true)
buf=1000;
else if(Button2->Checked==true)
buf=1400;
else {
if(Edit1->Text<1)
Edit1->Text=1;
buf=StrToInt(Edit1->Text);
}
buf1=buf*1024l;
num=FileLength/(buf*1024L)+1;
Bar->Panels->Items[1]->Text="分割成"+IntToStr(num)+"个文件";
ListBox1->Items->Clear();
ListBox1->Items->Add(ChangeFileExt(Path+FileName,".bat"));
for (int i=0;i<num;i++)
ListBox1->Items->Add(ChangeFileExt(Path+FileName,"."+IntToStr(i)));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit1->Enabled=false;
Edit1Click(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit1->Enabled=false;
Edit1Click(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Edit1->Enabled=true;
Edit1Click(Sender);
}
//---------------------------------------------------------------------------
xiaoshi0 2004-07-29
  • 打赏
  • 举报
回复
给我文件的扩展名和你的邮箱,我帮你做一个好了!
templez 2004-07-29
  • 打赏
  • 举报
回复
up
dhfly 2004-07-29
  • 打赏
  • 举报
回复
duhf03@st.lzu.edu.cn
dreamjin 2004-07-29
  • 打赏
  • 举报
回复
看楼上的代码,有H文件,可以找到控件,不过,有一个窗体就可以了,主要是文件操作函数的使用。
lizhoulun 2004-07-29
  • 打赏
  • 举报
回复
onlyfangzhou@263.net 我想有原代码和控件!谢谢

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧