Traverse all current and lower-level directorys, and record as XML files

xiaoxiao2021-03-06  109

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Xml; namespace WindowsApplication2 {///

/ Summary of // Form1. /// public class form1: system.windows.forms.form {private system.windows.forms.button button1; /// // / / The designer variable. /// private system.componentmodel.container components = null; const string mypath = @ "d: / nba2004"; xmlDocument doc = new xmldocument ();

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 () {this.button1 = new system.windows.forms.button (); this.suspendlayout (); // // button1 // this.button1.location = new system. Drawing.Point (192, 232); this.button1.name = "button1"; this.button1.size = new system.drawing.size (88, 24); this.button1.tabindex = 0; this.button1.text = "Button1"; this.button1.click = new system.eventhandler (this.button1_click1); // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new System.drawing.size (292, 273); this.Controls.add (this.button1); this.name = "form1"; this.text = "form1"; this.ResumeLayout (false);} #ENDREGION

///

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

private void button1_Click1 (object sender, System.EventArgs e) {string MyPath = mypath.ToUpper (); doc.LoadXml ( " "); GetFileInfo (MyPath, doc .DocumentElement); doc.Save (@ "d: /fileinfo.xml");} private void GetFileInfo (string strpath, System.Xml.XmlNode node) {DirectoryInfo DirInfo = new DirectoryInfo (strpath); foreach (DirectoryInfo dirinfo in DirInfo .Getdirectories ()) {xmlelement elem = doc.createElement ("Dir"); elem.setttribute ("name", dirinfo.name); elem.setttribute ("LastWritetime", Dirinfo.lastwrittime.toString ()); Node. AppendChild (elem); GetFileInfo (dirinfo.FullName, elem);} foreach (FileInfo fileinfo in DirInfo.GetFiles ()) {XmlElement elem = doc.CreateElement ( "file"); elem.SetAttribute ( "Name", fileinfo.Name ); Elem.setttribute ("lastwritetime", fileinfo.lastwrittime.tostring ()); elem.setttribute ("length", fileinfo.length.tostring ()); node.appendchild (elem);}}}}

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

New Post(0)