日期:2014-05-18 浏览次数:20827 次
// 调用 var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(......); var fdns = xmlDoc.SelectSingleNode("root"); Select(fdns); // 两个方法 private static void Select(XmlNode node) { var dns = node.SelectNodes("folder"); foreach (XmlNode item in dns) { Make(item); } var fns = node.SelectNodes("file"); foreach (XmlNode item in fns) { Make(item); } } private static void Make(XmlNode node) { var path = node.SelectSingleNode("path").InnerText; var ct = DateTime.Parse(node.SelectSingleNode("created").InnerText); var mt = DateTime.Parse(node.SelectSingleNode("modified").InnerText); FileSystemInfo fsi = null; switch (node.Name) { case "file": { Directory.CreateDirectory(Path.GetDirectoryName(path)); using (var stream = File.Open(path, FileMode.Create)) { stream.WriteByte(0); } fsi = new FileInfo(path); break; } case "folder": { fsi = Directory.CreateDirectory(path); break; } default: break; } fsi.CreationTime = ct; fsi.LastWriteTime = mt; Select(node); }