//说明://1、些工程是用于批量处理文件相关信息的添加//2、文件只做一些简单的操作,现只支持*.CS文件//3、没有对文件进行是否存在版本信息的判断。using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.IO;using System.Text;namespace WriteCopyRight...{ /**//// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form ...{ private System.Windows.Forms.FolderBrowserDialog folder; private System.Windows.Forms.TextBox txtFold; private System.Windows.Forms.Button btn_brow; private System.Windows.Forms.Button button1; private string ErrorInfo=null; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label9; private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox txtBuilder; private System.Windows.Forms.TextBox txtObjInfo; private System.Windows.Forms.TextBox txtObjName; private System.Windows.Forms.TextBox txtRight; private System.Windows.Forms.TextBox txtPhone; private System.Windows.Forms.TextBox txtTime; private System.Windows.Forms.TextBox txtMail; private System.Windows.Forms.TextBox txtSite; private System.Windows.Forms.TextBox txtRightInfo; /**//// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public enum filetype ...{ cs, html, aspx, java, txt, xml } public Form1() ...{ // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /**//// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) ...{ if( disposing ) ...{ if (components != null) ...{ components.Dispose(); } } base.Dispose( disposing ); } Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码 /**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() ...{ this.folder = new System.Windows.Forms.FolderBrowserDialog(); this.txtFold = new System.Windows.Forms.TextBox(); this.btn_brow = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.txtBuilder = new System.Windows.Forms.TextBox(); this.txtObjInfo = new System.Windows.Forms.TextBox(); this.txtObjName = new System.Windows.Forms.TextBox(); this.txtRight = new System.Windows.Forms.TextBox(); this.txtPhone = new System.Windows.Forms.TextBox(); this.txtTime = new System.Windows.Forms.TextBox(); this.txtMail = new System.Windows.Forms.TextBox(); this.txtSite = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.txtRightInfo = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // txtFold // this.txtFold.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtFold.Enabled = false; this.txtFold.Location = new System.Drawing.Point(16, 8); this.txtFold.Name = "txtFold"; this.txtFold.Size = new System.Drawing.Size(248, 21); this.txtFold.TabIndex = 0; this.txtFold.Text = ""; // // btn_brow // this.btn_brow.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btn_brow.Location = new System.Drawing.Point(272, 8); this.btn_brow.Name = "btn_brow"; this.btn_brow.TabIndex = 1; this.btn_brow.Text = "浏览"; this.btn_brow.Click += new System.EventHandler(this.btn_brow_Click); // // button1 // this.button1.Location = new System.Drawing.Point(272, 384); this.button1.Name = "button1"; this.button1.TabIndex = 2; this.button1.Text = "添写"; this.button1.Click += new System.EventHandler(this.button1_Click); // // txtBuilder // this.txtBuilder.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtBuilder.Location = new System.Drawing.Point(75, 66); this.txtBuilder.Name = "txtBuilder"; this.txtBuilder.Size = new System.Drawing.Size(91, 21); this.txtBuilder.TabIndex = 3; this.txtBuilder.Text = ""; // // txtObjInfo // this.txtObjInfo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtObjInfo.Location = new System.Drawing.Point(75, 92); this.txtObjInfo.Multiline = true; this.txtObjInfo.Name = "txtObjInfo"; this.txtObjInfo.Size = new System.Drawing.Size(270, 60); this.txtObjInfo.TabIndex = 4; this.txtObjInfo.Text = ""; // // txtObjName // this.txtObjName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtObjName.Location = new System.Drawing.Point(75, 37); this.txtObjName.Name = "txtObjName"; this.txtObjName.Size = new System.Drawing.Size(271, 21); this.txtObjName.TabIndex = 5; this.txtObjName.Text = ""; // // txtRight // this.txtRight.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtRight.Location = new System.Drawing.Point(75, 250); this.txtRight.Name = "txtRight"; this.txtRight.Size = new System.Drawing.Size(269, 21); this.txtRight.TabIndex = 6; this.txtRight.Text = ""; // // txtPhone // this.txtPhone.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtPhone.Location = new System.Drawing.Point(75, 220); this.txtPhone.Name = "txtPhone"; this.txtPhone.Size = new System.Drawing.Size(269, 21); this.txtPhone.TabIndex = 7; this.txtPhone.Text = ""; // // txtTime // this.txtTime.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtTime.Location = new System.Drawing.Point(237, 64); this.txtTime.Name = "txtTime"; this.txtTime.Size = new System.Drawing.Size(109, 21); this.txtTime.TabIndex = 8; this.txtTime.Text = ""; // // txtMail // this.txtMail.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtMail.Location = new System.Drawing.Point(75, 190); this.txtMail.Name = "txtMail"; this.txtMail.Size = new System.Drawing.Size(269, 21); this.txtMail.TabIndex = 9; this.txtMail.Text = ""; // // txtSite // this.txtSite.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtSite.Location = new System.Drawing.Point(75, 160); this.txtSite.Name = "txtSite"; this.txtSite.Size = new System.Drawing.Size(270, 21); this.txtSite.TabIndex = 10; this.txtSite.Text = ""; // // label1 // this.label1.Location = new System.Drawing.Point(16, 42); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(56, 16); this.label1.TabIndex = 11; this.label1.Text = "产品名:"; // // label2 // this.label2.Location = new System.Drawing.Point(20, 166); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(48, 16); this.label2.TabIndex = 12; this.label2.Text = "网站:"; // // label3 // this.label3.Location = new System.Drawing.Point(18, 96); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(46, 16); this.label3.TabIndex = 13; this.label3.Text = "描述:"; // // label4 // this.label4.Location = new System.Drawing.Point(17, 69); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(48, 14); this.label4.TabIndex = 14; this.label4.Text = "作者:"; // // label5 // this.label5.Location = new System.Drawing.Point(185, 69); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(48, 16); this.label5.TabIndex = 15; this.label5.Text = "时间 :"; // // label6 // this.label6.Location = new System.Drawing.Point(21, 191); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(48, 16); this.label6.TabIndex = 16; this.label6.Text = "邮箱:"; // // label7 // this.label7.Location = new System.Drawing.Point(21, 223); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(48, 16); this.label7.TabIndex = 17; this.label7.Text = "电话:"; // // label9 // this.label9.Location = new System.Drawing.Point(23, 281); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(72, 24); this.label9.TabIndex = 19; this.label9.Text = "版权说明:"; // // label10 // this.label10.Location = new System.Drawing.Point(22, 253); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(48, 16); this.label10.TabIndex = 20; this.label10.Text = "版权:"; // // txtRightInfo // this.txtRightInfo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtRightInfo.Location = new System.Drawing.Point(72, 298); this.txtRightInfo.Multiline = true; this.txtRightInfo.Name = "txtRightInfo"; this.txtRightInfo.Size = new System.Drawing.Size(272, 80); this.txtRightInfo.TabIndex = 21; this.txtRightInfo.Text = ""; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(368, 411); this.Controls.Add(this.txtRightInfo); this.Controls.Add(this.label10); this.Controls.Add(this.label9); this.Controls.Add(this.label7); this.Controls.Add(this.label6); this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Controls.Add(this.txtSite); this.Controls.Add(this.txtMail); this.Controls.Add(this.txtTime); this.Controls.Add(this.txtPhone); this.Controls.Add(this.txtRight); this.Controls.Add(this.txtObjName); this.Controls.Add(this.txtObjInfo); this.Controls.Add(this.txtBuilder); this.Controls.Add(this.button1); this.Controls.Add(this.btn_brow); this.Controls.Add(this.txtFold); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /**//// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() ...{ Application.Run(new Form1()); } 浏览文件夹#region 浏览文件夹 private void btn_brow_Click(object sender, System.EventArgs e) ...{ this.folder.ShowNewFolderButton = false; this.folder.ShowDialog(); this.txtFold.Text = this.folder.SelectedPath.ToString(); } #endregion 产品信息#region 产品信息 /**//// <summary> /// 信息内容 /// </summary> /// <param name="begin">头标记</param> /// <param name="end">尾标记</param> /// <returns>返回信息内容对象</returns> private StringBuilder AddFile(string begin,string end) ...{ System.Text.StringBuilder strbuilder = new System.Text.StringBuilder(); strbuilder.Append(begin+" "); strbuilder.Append("产品名:"+this.txtObjName.Text+" "); strbuilder.Append("作者:"+this.txtBuilder.Text+" "); strbuilder.Append("时间:"+this.txtTime.Text+" "); strbuilder.Append("描述:"+this.txtObjInfo.Text+" "); strbuilder.Append("网站:"+this.txtSite.Text+" "); strbuilder.Append("邮箱:"+this.txtMail.Text+" "); strbuilder.Append("电话:"+this.txtPhone.Text+" "); strbuilder.Append("版权:"+this.txtRight.Text+" "); strbuilder.Append("版权说明:"+this.txtRightInfo.Text+" "); strbuilder.Append(end+" "); return strbuilder; } #endregion 读取文件添加信息#region 读取文件添加信息 /**//// <summary> /// 读取文件写入描述信息 /// </summary> /// <param name="path">路径</param> /// <param name="type">要操作文件类型 例:*.cs,*.aspx,*.txt,*.java</param> /// <param name="begin">文件标记头 例:/*</param> /// <param name="end">文件标记尾 例:*/</param> private void TestToFile(string path,string type,string begin,string end) ...{ try ...{ System.IO.DirectoryInfo di = new DirectoryInfo(path); System.IO.DirectoryInfo []dif = di.GetDirectories(); System.IO.FileInfo []fi =di.GetFiles(type); for(int i=0 ;i<fi.Length;i++) ...{ System.IO.StreamReader sr= new StreamReader(fi[i].FullName); string strfiles = sr.ReadToEnd(); sr.Close(); System.IO.StreamWriter sw = new StreamWriter(fi[i].FullName,false); sw.WriteLine(this.AddFile(begin,end).ToString()); sw.WriteLine(strfiles); sw.Close(); } for(int j=0;j<dif.Length;j++) ...{ this.TestToFile(dif[j].FullName,type,begin,end); } } catch(Exception ex) ...{ this.ErrorInfo = ex.ToString(); } } #endregion 执行添加#region 执行添加 private void button1_Click(object sender, System.EventArgs e) ...{ this.TestToFile(this.txtFold.Text,"*.cs","/*","*/"); if (this.ErrorInfo!=null) ...{ MessageBox.Show("文件读取时出错!","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); } else ...{ MessageBox.Show("成功","Info",MessageBoxButtons.OK,MessageBoxIcon.Information); } } #endregion }}