C # file splitter

xiaoxiao2021-03-06  82

When combined, two layers of copy commands can be combined, and some files can be combined. In fact, the general length of the test command line can theoretically realize the combination of unlimited split files, but the practical value is not high, and the demolition of 10,000 documents. Not only is this single-threaded method, not only the efficiency is low, but it should be divided and combined with a better algorithm. This program can eventually be classified as "toys". Using system.drawing; using system.componentmodel; using system.windows.form; using system.data;

A summary description of Namespace filesplit {///

/// form1. /// public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.OpenFileDialog ofd; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; /// /// required Designer variable. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {this.textBox1 = new System.Windows.Forms.TextBox (); this.textBox2 = new System.Windows.Forms.TextBox (); this.button1 = new System. Windows.Forms.Button (); this.Button2 = new system.windows.Forms.Button (); this.ofd = new system.windows.forms.openfiledialog (); this.label1 = new system.windows.formel1 = new system.windows.forms.label (); This.Label2 = new system.windows.forms.label (); this.suspendlayout (); /// textBox1 // this.textbox1.borderStyle = system.windows.Forms.Borderstyle.FixedSingle; this.textbox1 .Location = new system.drawing.point (16, 16); this.textbox1.name = "textbox1"; this.textBox1.readonly = true; this.textbox1.size = new system.drawing.size (376, 21) "This.TextBox1.tabindex = 0; this.textBox1.text =" file path "; // // textbox2 // this.textBox2.Location = new system.drawing.point (56, 48); this.textbox2.name = "TextBox2"; this.textbox2.size = new system.drawing.size (72, 21); this.textbox2.tabind EX = 1; this.TextBox2.text = ""; // // button1 // this.button1.flatstyle = system.windows.Forms.Flatstyle.System; this.button1.location = new system.drawing.point (200 , 48); this.button1.name = "button1"; this.button1.size = new system.drawing.size (272, 24); this.button1.tabindex = 2; this.button1.text = "split" ; this.button1.Click = new System.EventHandler (this.button1_Click); // // button2 // this.button2.FlatStyle = System.Windows.Forms.FlatStyle.System; this.button2.Location = new System. Drawing.point (400, 16); this.Button2.name =

"Button2"; this.button2.size = new system.drawing.size (72, 24); this.button2.tabindex = 3; this.button2.text = "Browse"; this.button2.click = new system. EventHandler (this.button2_click); // // label1 // this.label1.location = new system.drawing.point (16, 48); this.label1.name = "label1"; this.label1.size = new system .Drawing.size (32, 23); this.label1.tabindex = 4; this.label1.text = "size"; /// label2 // this.label2.location = new system.drawing.point (136, 48); this.label2.name = "label2"; this.label2.size = new system.drawing.size (56, 16); this.label2.tabindex = 5; this.label2.text = "kb"; / / // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (498, 79); this.controls.add (this.label2); this .Controls.add (this.Label1); this.controls.add (this.button2); this.Controls.add (this.button1); this.controls.add (this.TextBox2); this.controls.add (This.Add (this .TextBox1); this.Formbord erStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Form1"; this.Text = "Spliter"; this.ResumeLayout (false);} #endregion

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

private void button2_Click (object sender, System.EventArgs e) {if (this.ofd.ShowDialog () = System.Windows.Forms.DialogResult.OK!) {return;} this.textBox1.Text = ofd.FileName;}

Private void button1_click (object sender, system.eventargs e) {try {INT i = 1; try {i = int.parse (this.textBox2.text); if (i <= 0) {system.exception EE = New Exception (); throw ee;} i * = 1000;} catch {i = 0; system.windows.Forms.MessageBox.show ("Input Split Number is incorrect"); return;} #Region "Assign folder" INT Count = 1; String Workpath = OFD.FileName.toString () "split"; while (true) {if (! system.io.directory.exists (workpath) {@}} else {ix (! system.io .Directory.exists (Workpath "_" count.toWorkPath = "_" count.to} else {count ;}}} system.io.directory.createdirectory (WorkPath) #Ndregion system.io.filestream f = new system.io.filestream (OFD.FileName, System.IO.FileMode.Open); System.Io.binaryReader R = new system.io.binaryReader (f);

Long L = f.length; long x = 0; int filecount = 1;

FOR (; x

System.io.streamwriter T = new system.io.streamwriter (System.IO.File.Open (Workpath // " " Combined file .bat ", system.io.filemode.create), System.Text.Encoding. Default);

T.WRITELINE ("@ echo off"); T.Write ("copy"); int Tempcount = 0; for (int for2 = 1; for2

}

T.Write ("Copy"); for (int for2 = 0; for2

For (int for2 = 0; for2

T. close (); filecount- = 1;

System.Windows.Forms.MessageBox.show ("Split file creation has been completed, split into" filecount.toString () "section");} catch (system.exception ee) {system.windows.forms. Messagebox.show ("There is a mistake in operation, no splitting:" ee.Message); gc.collect ();}}

Private string getFileName (string str) {int firstname = 0; string result = ""; for (int i = str.length-1; i> = 0; I -) {IF (STR [i] == '/ / ') {Firstname = i; break;}} for (int i = firstname 1; i

} Return Result;

}

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

New Post(0)