📄 frmfilecombinate.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace FileComb
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmFilesCombinate : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblSource;
private System.Windows.Forms.TextBox txtSource;
private System.Windows.Forms.Button btnDo;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.TextBox txtDest;
private System.Windows.Forms.Label lblDest;
private System.Windows.Forms.ListBox lstInfo;
private System.Windows.Forms.ProgressBar procNumber;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmFilesCombinate()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblSource = new System.Windows.Forms.Label();
this.txtSource = new System.Windows.Forms.TextBox();
this.btnDo = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.txtDest = new System.Windows.Forms.TextBox();
this.lblDest = new System.Windows.Forms.Label();
this.lstInfo = new System.Windows.Forms.ListBox();
this.procNumber = new System.Windows.Forms.ProgressBar();
this.SuspendLayout();
//
// lblSource
//
this.lblSource.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblSource.Location = new System.Drawing.Point(8, 16);
this.lblSource.Name = "lblSource";
this.lblSource.Size = new System.Drawing.Size(80, 12);
this.lblSource.TabIndex = 0;
this.lblSource.Text = "源文件路径:";
//
// txtSource
//
this.txtSource.Location = new System.Drawing.Point(96, 8);
this.txtSource.Name = "txtSource";
this.txtSource.Size = new System.Drawing.Size(344, 21);
this.txtSource.TabIndex = 1;
this.txtSource.Text = "";
//
// btnDo
//
this.btnDo.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnDo.Location = new System.Drawing.Point(296, 72);
this.btnDo.Name = "btnDo";
this.btnDo.Size = new System.Drawing.Size(144, 26);
this.btnDo.TabIndex = 2;
this.btnDo.Text = "执行合并...";
this.btnDo.Click += new System.EventHandler(this.btnDo_Click);
//
// btnExit
//
this.btnExit.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnExit.Location = new System.Drawing.Point(296, 224);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(144, 26);
this.btnExit.TabIndex = 4;
this.btnExit.Text = "退出";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// txtDest
//
this.txtDest.Location = new System.Drawing.Point(96, 40);
this.txtDest.Name = "txtDest";
this.txtDest.Size = new System.Drawing.Size(344, 21);
this.txtDest.TabIndex = 6;
this.txtDest.Text = "";
//
// lblDest
//
this.lblDest.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblDest.Location = new System.Drawing.Point(8, 48);
this.lblDest.Name = "lblDest";
this.lblDest.Size = new System.Drawing.Size(80, 12);
this.lblDest.TabIndex = 5;
this.lblDest.Text = "目标文件路径:";
//
// lstInfo
//
this.lstInfo.ItemHeight = 15;
this.lstInfo.Location = new System.Drawing.Point(8, 104);
this.lstInfo.Name = "lstInfo";
this.lstInfo.Size = new System.Drawing.Size(432, 109);
this.lstInfo.TabIndex = 7;
//
// procNumber
//
this.procNumber.Location = new System.Drawing.Point(8, 72);
this.procNumber.Name = "procNumber";
this.procNumber.Size = new System.Drawing.Size(280, 24);
this.procNumber.TabIndex = 8;
this.procNumber.Visible = false;
//
// frmFilesCombinate
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(451, 255);
this.Controls.Add(this.procNumber);
this.Controls.Add(this.lstInfo);
this.Controls.Add(this.txtDest);
this.Controls.Add(this.lblDest);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnDo);
this.Controls.Add(this.txtSource);
this.Controls.Add(this.lblSource);
this.Font = new System.Drawing.Font("Times New Roman", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmFilesCombinate";
this.Text = "文件合并";
this.Load += new System.EventHandler(this.frmFilesCombinate_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmFilesCombinate());
}
private void frmFilesCombinate_Load(object sender, System.EventArgs e)
{
}
private void btnDo_Click(object sender, System.EventArgs e)
{
//源文件路径
string strSrc;
//目标文件路径
string strDest;
string tempdata;
int ii;
int Num;
int TotalNum;
strSrc=txtSource.Text.Trim();
strDest=txtDest.Text.Trim()+"\\total.txt";
//获取winDir1路径下所有文件列表
string[] dirs = Directory.GetFiles(strSrc,"*.TXT");
//文件总数
TotalNum = dirs.GetUpperBound(0);
//建立或打开目标文件,准备读
StreamWriter writer = new StreamWriter(strDest);
ii=0;
Num=0;
procNumber.Visible=true;
foreach(string dir in dirs)
{
Num=Num+1;
AddListItem("合并文件"+dir+"......");
StreamReader reader=new StreamReader(dir);
try
{
reader.ReadLine();
do
{
tempdata=reader.ReadLine();
tempdata=tempdata.Trim();
writer.WriteLine(tempdata);
}
while(reader.Peek() != -1);
ii=ii+1;
}
catch( Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
reader.Close();
procNumber.Visible=false;
}
procNumber.Value = Num/TotalNum*100;
procNumber.Refresh();
}
procNumber.Visible =false;
//操作结束信息
AddListItem("合并操作结束");
AddListItem("本次操作共有"+ii.ToString()+"个文件合并到文件TOTAL.TXT中去");
writer.Close();
}
//为列表框添加新项
private void AddListItem(string value)
{
lstInfo.Items.Add(value);
lstInfo.Refresh();
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -