Implement file cutting machine with C Builder 5.0
Author: Wudalianchi Maming Chen
First, the question is proposed:
I believe that many friends have encountered such problems, how to copy a file larger than a floppy disk to the floppy disk, may readers will think of the tools in DOS and Restore, but these two tools require the DOS version must Consisten to, otherwise it will not be recovered after the backup, and it is very inconvenient to use, is there any convenient tool? The answer is a positive file cutting machine. There are many such tools on the Internet, which can easily split any type, file with any size. And automatically provide a merger batch file. If you don't have this type of software in your hand, you want to divide the software, then learn how to use the C Builder design file cutter.
Second, the program design principle
We know that the file can be split, because all files are stored in binary form, and then read processing according to the corresponding provisions of the file system. Based on this principle, we read and write all types of files with binary, and then recombine the divided files in binary format, so that the segmentation and merge of files are achieved. (Note: You can also merge with the internal command of DOS. The format is as follows: Copy FileName1 / B FileName2 / B ... FileNamen / B FileName Here FileName1 - FileNamen is divided by the divided file; FileName is the merger The file name; / b is a copy of the file in binary form.)
Third, the program design process and detailed explanation
First we create a new project in C Builder, the store and name the project file for fgj.bpr, the named unit file is filefgj.h. Then reopen the project, change the form of the form of the form of the form of the "Ming Chen Software Cutting Machine 1.0", the Font Attribute value is "Song" "No. 9", the position attribute value is POSCREENCENTER, the purpose is to make the form in the form; Add a FileListBox control (in the Win3.1 tab), a DireToryListBox control (in the Win3.1 tab), a DriveComboX control (in the win 3.1 tab) and modify the dirlist property is DirectoryListBox1, a filtercomboBox Win 31. Tags) and modify the filelist property to fileListBox1, so that the four regions have been established between the four regulations on the file directory, all controls will change with one of them, we don't have to consider more Detail issues are very convenient (ie, the functionality in the WinodWS File Manager). In order to filter different types of files, we also need to modify the FilterComboBox's filter attributes as follows:
Filter Name Filter
Executive file (* .exe) * .exe
Compressed file (* .zip; *. RAR; *. Arj; *. CAB) * .zip; *. RAR; *. Arj; *.
DVD file (* .dat; *. Mpg; *. Mpeg) * .dat; *. Mpg; *. Mpeg; *. MiV; *. Mp2; *. Mpa; *. MPE
Image file (* .bmp; *. Jpg; *. Gif) * .bmp; *. ICO; *. WMF; *. EMF; *. Jpg; *. Gif
All files *. *
Add a ComboBox Combination box (used to select or enter the size of the file), set the ComboBox's style property value for csdropdown, in order to provide the user selecting the split file size, set the link of the company, the LTEMS attribute value is as follows: (Note: This value can be set arbitrarily, the author is set here into a standard floppy disk capacity) 1400
1200
720
360
Then add three EDIT components, add a listbox1 list box, add 3 bitmap button components BitBTN and set their CAPTION attribute value to "cut file", "About Program", "Exit Program"; Add a progress bar ProgressBar1 And set its min attribute value of 1, the max property value is 100, the position attribute value is 1; add three text tag label and set its CAPTION attribute value "" The source ID of your choice is: "," source The file is divided into: "," Please enter the generated first target file name: ". Then set the layout of each component as shown in Figure 1.
Below we start designing code:
First open the filefgj.h header file, add #include "fstream.h" on its head (using the unit file when generating batch files) and then add the following variables after private: // user declarations
INT filehandle; // file handle variable
INT filelength; // Source file size variable
INT NUM; // Source file number after segmentation
INT IBYTESREAD; // Temporary variable
Char * pszbuffer; // temporary variable
INT buf; // file buffer variable 1
INT buf1; // file buffer variable 2
Then double-click the response event of the FileListBox component to write the component as follows:
Void __fastcall tform1 :: filelistbox1change (TOBJECT * Sender)
{
Edit1-> text = filelistbox1-> filename; // Show your selection file name in Edit1
Edit3-> text = ChangefileExt (filelistbox1-> filename, "." INTSTOSTR (1)); // Used to display the first file name after segmentation
BUF = ((ComboBoBox1-> text) .toint ()); // Setting the file buffer as the size selected or entered in the combo box
BUF1 = BUF * 1024L; // Transform the buffer into bytes
FileHandle = fileopen (edit1-> text, fmopenread); // Open the file handle
FileLength = Fileseek (FileHandle, 0, 2); // Test file length
Num = fileLength / buf1 1; // calculate the number of files
Edit4-> text = "Source file is split into" INTSTOSTR (NUM) "file"; // Display the number of files in Edit4
FileClose (FileHandle); // Close the file
Listbox1-> items-> clear (); // Clear list
ListBox1-> items-> add (edit3-> text, ".,"). C_str ()); / / // Show the generated merge batch file name in the list 1
For (INT i = 1; i <= NUM; i )
{
Listbox1-> items-> add (edit3-> text, "." INTOSTR (i)))); // Show all split file name paths in the list}
}
/ / -------------------------------------------------------------------------------------------- -------------
Then double-click the ComboBox1 component to write the following response code: (and set the onchange, the response code of the Onenter to this code)
Void __fastcall tform1 :: ComboBox1click (Tobject * Sender)
{
BUF = (ComboBoX1-> text.Toint ()); // assigns the value in the combo box to the file buffer variable
BUF1 = BUF * 1024L;
Num = filelength / (buf * 1024L) 1; / / calculate the number of files after segmentation
Edit4-> text = NUM; // Display the number of files in Edit4
Listbox1-> items-> clear ();
Listbox1-> items-> add (changefileext, ". BAT"). C_str ());
For (int i = 0; i { Listbox1-> items-> add (edit3-> text, "." INTOSTR (i)))); // Show all files after segmentation in the list box } } / / -------------------------------------------------------------------------------------------- -------------------------------------------------- ------------ Double-click the cutting file button to write the cut button's response function as follows: Void __fastcall tform1 :: bitbtn1click (Tobject * Sender) { FileLength <= BUF1) {ShowMessage ("File is less than the size of the split, no split"); Return;} ProgressBar1-> max = NUM; // Set the progress strip status ProgressBar1-> Position = 1; 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); // Open the file handle Fileseek (FileHandle, BUF1 * (I-1), 0); // Positioning the read file location IF (FileHandle, PszBuffer, Temp)! = Temp) ShowMessage ("Read Error!"); FILECLOSE (FileHandle); // Close source file Progressbar1-> Position = i; Label5-> caption = "has been performed:" ANSISTRING (ProgressBar1-> Position * 100 / NUM) "%"; INT HANDLE = FileCreate ((edit3-> text, "." INTOSTR (i)))))))))))); // Generate split target files IF (FileWrite (Handle, PszBuffer, Temp)! = Temp) ShowMessage (" Write Error! "); // Write the software to the divided target file FILECLOSE (Handle); // Close the target file } ProgressBar1-> Position = 1; Label5-> CAPTION = "Complete Split"; // ---------------------------------- The following is the batch file code when the merge file is automatically generated. ANSISTRING NAME = "/ B"; For (INT i = NUM; I> = 1; I -) { Ansistring nn = changefileext (edit3-> text, "." INTSTR (i)); IF (filelistbox1-> filename) .length ()> 12) {nn = extractshortpathname (fileListbox1-> filename); NN = ChangefileExt (nn, "." INTOSTR (i)); } IF (i == 1) {Name = extractFileName (NN) Name;} Else { Name = "/ b " extractfilename (nn) Name;} } Ansistring hbbat = "Copy" Name "" ExtractFileName (fileListbox1-> filename); FSTREAM FILE; File.open (ChangefileExt, ". BAT"). c_str ()); File << " @echo off "<< '/ n'; File << "Echo Created by MC-SPLITE READ SPLIT FILES:" << '/ n'; File << hbbat.c_str (); File.Close (); } / / -------------------------------------------------------------------------------------------- ---------------------------- Double-click the "About Program" bitmap button to write "About Program" The response code is as follows: Void __fastcall tform1 :: bitbtn2click (TOBJECT * SENDER) { SHELLABOUT (Handle, "," / N Mingchen Document Cutting Machine (V1.00) Copyright (C) Ma Mingchen / N Address: Heilongjiang Province Five Dabai Pool Statistics Bureau 2002.6 / N Tel: 6322348 Email: 6322348 Email: M@0451.com ", null); // Use the API function to display version of the board information } Double-click the "Exit Program" bitmap button to write the "exit program" The response code is as follows: Void __fastcall tform1 :: bitbtn3click (Tobject * sender) { CLOSE (); } Now we can press F9 to run, how to split / merge a few files, the effect is not inferior to such shared software online! I don't care if I personally try it. If you want to publish this program separately, you can open the Project | Option. Dialog to remove the package | Build With runtime packages, Linker | Create Debug Infomation and Linker | Use Dynamic RTL Select before compiling and generates no dynamic The link library can run separately.