private static void ProcesoDir(KnowledgeBase KB, string directoryArg, string newDir, string generator, IOutputService output) { string outputFile = KB.UserDirectory + @"\KBdoctorEv2.xslt"; XslTransform xslTransform = new XslTransform(); KBDoctorOutput.Message("Cargando archivo xslt: " + outputFile); xslTransform.Load(outputFile); KBDoctorOutput.Message("Archivo xslt cargado correctamente."); string fileWildcard = @"*.xml"; var searchSubDirsArg = System.IO.SearchOption.AllDirectories; string[] xFiles = System.IO.Directory.GetFiles(directoryArg, fileWildcard, searchSubDirsArg); Hashtable colisiones = new Hashtable(); HashSet <string> colisionesStr = new HashSet <string>(); //Busco colisiones en los nombres de los archivos foreach (string x in xFiles) { string filename = Path.GetFileNameWithoutExtension(x); if (!colisiones.Contains(filename)) { List <string> paths = new List <string>(); paths.Add(x); colisiones[filename] = paths; } else { List <string> paths = (List <string>)colisiones[filename]; paths.Add(x); colisiones[filename] = paths; if (!colisionesStr.Contains(filename)) { colisionesStr.Add(filename); } } } //Me quedo sólo con el archivo más nuevo y cambio el nombre de todos los demás. foreach (string name in colisionesStr) { FileInfo newestFile = null; DateTime newestDate = new DateTime(1891, 09, 28); List <string> paths = (List <string>)colisiones[name]; List <FileInfo> oldfiles = new List <FileInfo>(); foreach (string path in paths) { FileInfo file = new FileInfo(path); if (file.LastWriteTime >= newestDate) { if (newestFile != null) { oldfiles.Add(newestFile); } newestDate = file.LastWriteTime; newestFile = file; } else { oldfiles.Add(file); } } int i = 1; foreach (FileInfo fileToRename in oldfiles) { string nombre = fileToRename.DirectoryName + '\\' + Path.GetFileNameWithoutExtension(fileToRename.Name) + i.ToString() + ".oldxml"; FileInfo filerenamed = new FileInfo(nombre); if (filerenamed.Exists) { try { filerenamed.Delete(); fileToRename.MoveTo(nombre); } catch (Exception e) { } } i++; } } xFiles = System.IO.Directory.GetFiles(directoryArg, fileWildcard, searchSubDirsArg); foreach (string x in xFiles) { if (!Path.GetFileNameWithoutExtension(x).StartsWith("Gx0")) { try { string xTxt = newDir + generator + Path.GetFileNameWithoutExtension(x) + ".nvg"; string xmlstring = Utility.AddXMLHeader(x); string newXmlFile = x.Replace(".xml", ".xxx"); File.WriteAllText(newXmlFile, xmlstring); xslTransform.Transform(newXmlFile, xTxt); File.Delete(newXmlFile); } catch (Exception e) { output.AddErrorLine(e); } } } }