Command Line | Design Shareware There are many beautiful interface file segmentation procedures, a large file divided into several smaller files, save separately, when needed to merge into the original file, is often a necessary tool.
This article uses the C # language of Microsoft's Visual Studio. NET development environment to also design a file separator and run it as a DOS command line, as simple as using the Copy command. You can also learn about the principle of file segmentation and how the. NET Framework reads and writes files.
Create a new Visual C # project, select Console application, project name is set to Filesplitcon, the system automatically generates Class1.cs files, and the following code is added to the appropriate area of Class1.cs:
Using System;
Using System.Data;
Using System.IO;
Namespace Filesplitcon
{
<summary>
Summary description of the CLASS1.
</summary>
Class Class1
{
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main (string[] args)
{
if (args[0]== "s")
{
int i;
FileStream FR = new FileStream (Args[1],filemode.open, FileAccess.Read);
int FileSize = Convert.ToInt32 (Fr. Length)/convert.toint32 (args[2]);
After compiling, the executable file is generated under Bin/debug, the size is only 6.5kb, and the execution program is copied to the path that the system can find, such as C:\Winnt (Windows2000 system), making it a system command.
Use the following method at the Command Prompt window (assuming the compiled executable is Filesplitcon.exe):
Split file:
Filesplitcon s to split file file name into several files
For example Filesplitcon S W2ksp3.exe 4 (split w2ksp3.exe into 4 files)
Merging files:
Filesplitcon m merged file name
The code is concise, using the StreamWriter and StreamReader objects, iterating through the files in byte, the first parameter args[0]= "s" to execute the split file code, args[0]= "M" to execute the merged file code.
Description
Split, in the same directory with the split file to generate each split file, file name is the original file name plus. 1,.2,.3, ... To generate a list file. List, record the file name of each split file generated;
For example, for Filesplitcon s W2ksp3.exe 4;
W2ksp3.exe.1
W2ksp3.exe.2
W2ksp3.exe.3
W2ksp3.exe.4
W2ksp3.exe.list
The contents of the W2ksp3.exe.list file are:
W2ksp3.exe.1
W2ksp3.exe.2
W2ksp3.exe.3
W2ksp3.exe.4
When merging, the
W2ksp3.exe.1
W2ksp3.exe.2
W2ksp3.exe.3
W2ksp3.exe.4
W2ksp3.exe.list
5 file copies in any directory, execute command:
Filesplitcon m W2ksp3.exe
Note: If a file cannot be divided into just a few files, the process of the above program is to write the remaining bytes to the new file, so for the above example command, if the W2ksp3.exe can not be divided into 4 files, then will generate 5 files, so the processing should be closer to the actual situation.
The above program is debugged in the Windows2000,visual studio. NET development environment, because the command-line approach is running quickly, dividing a 124M file into 4 files does not feel like waiting time.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.