public static int Iterate(string root) { var iterator = new DirectoryIterator(); iterator.iterate(root); return(iterator.count); }
public void IterateAllToConsole() { DirectoryIterator dirIter = new DirectoryIterator(_testPath); dirIter.ProcessFiles = true; dirIter.Iterate(new DirectoryIterator.Delegate(PrintDirsAndFiles)); }
private static void PrintDirsAndFiles(DirectoryIterator sender, DirectoryIterator.Args args) { string text; if (args.IsDirectory) { text = "DIR: {0}"; } else { text = "FILE: {0}"; } Console.WriteLine(text, args.Path); }
private bool CopyFolder(string SourceFolder, string DestinationFolder, bool MoveFiles = false) { string relPath; if (!Directory.Exists(DestinationFolder)) { Directory.CreateDirectory(DestinationFolder); } List <System.IO.FileInfo> files; DirectoryIterator di = new DirectoryIterator(); files = di.TraverseTree(SourceFolder, ".lnk"); foreach (System.IO.FileInfo lFile in files) { relPath = lFile.FullName.Replace(SourceFolder, DestinationFolder); try { if (!Directory.Exists(Path.GetDirectoryName(relPath))) { Directory.CreateDirectory(Path.GetDirectoryName(relPath)); } File.Copy(lFile.FullName, relPath, true); //Delete if copied (Move - used in backup before composition) if (MoveFiles == true) { File.Delete(lFile.FullName); } } catch (Exception ex) { AppLogger.WriteLine("Error while doing backup of file: \"" + lFile.FullName + "\"", LoggerSeverity.Error, ex); continue; } } return(true); }
public static void Main() { var catalogueXml = "../../XMLs/catalogue.xml"; // Task 2. Write program that extracts all different artists which are found in the catalog.xml. Console.WriteLine(CustomDomParser.GetAlbumsCount(catalogueXml)); // Task 3. Implement the previous using XPath. Console.WriteLine(XPath.GetAlbumsCount(catalogueXml)); // Task 4. Using the DOM parser write a program to delete from catalog.xml all albums having price > 20. var strippedCatalogueDom = CustomDomParser.DeleteAlbumsHigherThanSpecifiedPrice(catalogueXml, 20); // Task 5. Write a program, which using XmlReader extracts all song titles from catalog.xml. Console.WriteLine(StaxParser.ExtractSongTitles(catalogueXml)); // Task 6. Rewrite the same using XDocument and LINQ query. Console.WriteLine(LinqToXml.ExtractSongTitles(catalogueXml)); // Task 7. In a text file we are given the name, address and phone number of given person(each at a single line). var personDataTxt = "../../XMLs/person-id-info.txt"; var personXml = "../../XMLs/person-id.xml"; LinqToXml.CreateXmlDocFromTxt(personDataTxt, personXml); // Task 8. Write a program, which (using XmlReader and XmlWriter) reads the file catalog.xml and creates // the file album.xml, in which stores in appropriate way the names of all albums and their authors. var albumXml = "../../XMLs/albums.xml"; StaxParser.ExtractAlbums(catalogueXml, albumXml); // Task 9. Write a program to traverse given directory and write to a XML file its contents together with all subdirectories and files. // Set to traverse the Desktop. Try it out with any directory. var targetDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var outputUrlXmlWriter = "../../XMLs/directory-xml-writer.xml"; DirectoryIterator.TraverseXmlWriter(targetDirectory, outputUrlXmlWriter); // Task 10. Rewrite the last exercises using XDocument, XElement and XAttribute. // Set to traverse the Desktop. Try it out with any directory. var outputUrlXDoc = "../../XMLs/directory-xdoc.xml"; DirectoryIterator.TraverseXDoc(targetDirectory, outputUrlXDoc); // Task 11. Write a program, which extract from the file catalog.xml the prices for all albums, published 5 years ago or earlier. Console.WriteLine(XPath.ExtractPricesByYear(catalogueXml, 15)); // Task 12. Rewrite the previous using LINQ query. Console.WriteLine(LinqToXml.ExtractPricesByYear(catalogueXml, 15)); // Task 14. Write a C# program to apply the XSLT stylesheet transformation on the file catalog.xml using the class XslTransform. var catalogueXslt = "../../XMLs/catalogue-template.xslt"; var catalogueHtml = "../../XMLs/catalogue.html"; XsltConvertor.GenerateHtmlPageForCatalogueXml(catalogueXml, catalogueXslt, catalogueHtml); // Task 16. Using Visual Studio generate an XSD schema for the file catalog.xml. var catalogueXsd = "../../XMLs/catalogue.xsd"; Console.WriteLine(XsdValidator.ValidateXml(catalogueXml, catalogueXsd)); Console.WriteLine(XsdValidator.ValidateXml(personXml, catalogueXsd)); }
public void IterateDirsToConsole() { DirectoryIterator dirIter = new DirectoryIterator(_testPath); dirIter.Iterate(delegate(DirectoryIterator sender, DirectoryIterator.Args args) { Console.WriteLine(args.Path); }); }