Stream stream segmentation file in BCB

zhaozj2021-02-17  50

Nowadays, the source code of many divided file programs is written in VC, and also converts the code of VC to BCB, but the BCB encapsulates a lot of classes, which is more convenient and easy to operate.

This is the split file program I use to use the BCB using TMEMORYSTREAM and TFileStream. The key code is also a dozen words.

First put an OpenDialog and Button, Edit, write the following code in the click event in Button.

INT AIM_SIZE = 0; try {int Edit1_size = edit1-> text.Toint (); av_size = edit1_size;} catch (...) {return;} int K_1024 = 1024 * aim_size; if (! OpenDialog1-> execute () ) Return; string file_name = OpenDialog1-> filename;

IF (file_name == ") Button2Click (sender); if (! FileExists) file: // File is valid {showMessage (" invalid file "); return;} string file_path = extractFilePath (file_name); // file path // String file_ext = ExtractFileExt (file_name); file: // file suffix String file_Na = ExtractFileName (file_name); file: // filename try {TMemoryStream * pms = new TMemoryStream (); // original file pms-> LoadFromFile (file_name); PMS-> Seek (0, SOFROMBEGINNING); // Location Head INT SIZEMEM = (PMS-> Size) / K_1024; // n k

IF (SIZEMEM> 999) {showMessage ("file exceeds a scheduled number, unable to split / n, please expand file after division"); Return;

}

String batfile = "@ echo off / r / ncopy / b"; file: // Generate the content string n_i = ""; for (int i = 0; i

TMEMORYSTREAM * PMS_I = New TMEMORYSTREAM (); // Target File

PMS_I-> CopyFrom (PMS, K_1024); PMS_I-> Savetofile (file_na "." n_i); delete PMS_i;

N_i = (string) SIZEMEM; N_I = "00" n_i; n_i = n_i.substring (n_i.length () - 2, 3);

TMEMORYSTREAM * PMS_I = New TMEMORYSTREAM (); // Last file

PMS_I-> CopyFrom (PMS, PMS-> Size-SizeMem * K_1024); PMS_I-> SaveTofile (file_path file_na "." n_i); batfile = batfile file_na "." n_i; batfile = batfile "" File_NA Delete PMS_i; delete pms; try {tfilestream * mybat; mybat = new tfilestream (file_path file_na ". bat", fmcreate); char * bat = batfile.c_str (); mybat-> writebuffer (bat, batfile.length) )); Delete mybat;} catch (...) {}

ShowMessage ("file segmentation success");} catch (...) {showMessage ("file segmentation error");}

File: // There is also a .bat file is used for mergers, it is easy.

It is also very simple to use the flow merged file. If you are interested, I have just arrived with streaming.

Skilla: wyb45@sohu.com

转载请注明原文地址:https://www.9cbs.com/read-29524.html

New Post(0)