File splitter

zhaozj2021-02-08  235

File splitter

Li Guangqiang

The file splitter is a relatively practical tool. When we want to copy a file or picture larger than a disk capacity from another computer, you can experience it. The principle of the file splitter is actually very simple. It is generally this: first read the size of the file you want to divide, and use it to remove the capacity of each disk, draw the number of disk required, then start reading the content At the same time, establish a new file, put the read content into a new file, wait until the size of the new file is equal to the capacity of a disk, then set up another new file, continue to read the content of the source file, Put these contents into a highly established file, which is cycled until the end of the division. Of course, the divided files are required to be used to use, so the merge is essential. The merger process is this: read the segmentation files in turn and write it in the file you specified by adding.

The following is a specific implementation process:

#Include

#Include

#Include

Int main (int Argc, char * argv [])

{Void setFileName (Char * DEST, CHAR * SRC, INT I);

Char filename [100];

IF (argc == 1)

{CERR << "command is not" << endl;

Exit (1);

IF (argc == 2)

// The following is divided by the file code

{INT count = 1, disksize = 2048 * 705, disknum;

FSTREAM F2 (Argv [1], ios :: in & brvbarios :: binary & brvbarios :: nocreate; // Open the file to be split

IF (f2.fail ()) exit (1); // Exit

F2.seekg (0, ios :: end);

Streampos POS2 = f2.tellp ();

F2.seekg (0, ios :: beg);

Disknum = POS2 / Disksize;

IF (! disknum) exit (0);

// If the file is less than one disk capacity exits

IF (POS2% Disksize) DiskNum = DiskNum 1;

For (int b = 1; b

{int y;

SetFileName (FileName, Argv [1], B);

// Call the establishment file name function

FSTREAM F1 (filename, ios :: out & brvbarios :: binary);

// Establish a new file

DO {y = f2.get ();

// read data from the file to be divided

Count = count 1;

F1.write ((char *) & y, sizeof (char));}

/ / Write data to the new file

While ((y! = EOF) && (count <= disksize * b));

f1.close ();

f2.close ();

Else // The following is a file merge code

{INT X;

FSTREAM F (Argv [1], ios :: Out & Brvbarios :: App & Brvbarios :: binary;

For (int i = 2; I

{FSTREAM F1 (Argv [i], ios :: in & brvbarios :: binary & brvbarios :: nocreate;

IF (f1.fail ()) exit (1); x = f1.get ();

While (x! = EOF)

{F.Write (CHAR *) & X, Sizeof (char));

X = f1.get ();

f1.close ();

f.close ();}

// The following is a file name function

Void SetFileName (Char * Dest, Char * SRC, INT i)

{INT X, A = 0, B = 0;

Bool flag = false;

For (int i = 0; src [i]! = '/ 0'; i )

IF (src [i] == '.') Flag = true;

/ / Judgment whether the file contains an extension

If (flag) // If there is an extension, follow the following code.

{while (src [b]! = '.')

{DEST [B] = SRC [B];

B ;

A = B;

IF (i <= 9)

{x = i 48;

DEST [A] = (char) x;}

For (int i = 0; i <4; i )

{IF (src [b]! = '/ 0')

{a = a 1;

DEST [A] = SRC [B];

B = B 1;

Else Break;

DEST [A 1] = '/ 0';}

Else {// If there is no extension, press the following code processing

While (src [a]! = '/ 0')

{DEST [A] = SRC [A];

A = a 1;}

IF (i <= 9)

{x = i 48;

DEST [A] = CHAR (X);

DEST [A 1] = '/ 0';}}}

The above procedures are commissioned by Borland C 5.0 in Simplified Chinese Windows 98 SE. Due to the reason, this procedure saves a lot of things, such as the maximum to divide 9 files and a lot of error handling code. I only hope that this article can play a role in tiles, let the masters have better programs. This program can only be used under the command window, and the file name and the file name to be divided are entered when the program name and the file name to be split; the merged file name and the source name that you need to merge will be entered.

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

New Post(0)