using System.IO.Compression;
using System.Collections.Generic;
using ArchiveFlow.FileProcessor;
public static void Main()
var list = new List<string>();
var builder = new FileProcessorBuilder()
.FromFolder("./ZipFiles")
.ProcessAsText((file, text) =>
XDocument xdoc = XDocument.Parse(text);
string id = (string)xdoc.Root.Attribute("id");
string name = (string)xdoc.Root.Element("name");
var elements = xdoc.Root.Elements("element");
string elementValues = string.Join(", ", elements.Select(e =>
string idx = (string)e.Attribute("idx");
string value = (string)e;
return $"({idx},{value})";
string result = $"({id},{name}) -> elements [ {elementValues} ]";
var processor = builder.Build();
processor.ProcessFiles();
Console.WriteLine($"{countFiles} files have been processed by ArchiveFlow");
Console.WriteLine($"The resulting list contains {list.Count} elements, these are the first 10:");
for (int i = 0; i < 10; ++i)
Console.WriteLine(list[i]);
string outputDirectory = "ZipFiles";
Directory.CreateDirectory(outputDirectory);
int totalXmlFiles = 1000;
int zipCount = totalXmlFiles / xmlFilesPerZip;
for (int zipIndex = 1; zipIndex <= zipCount; zipIndex++)
string zipFileName = $"ZipFile_{zipIndex:D2}.zip";
string zipFilePath = Path.Combine(outputDirectory, zipFileName);
using (ZipArchive zipArchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create))
for (int xmlIndex = 1; xmlIndex <= xmlFilesPerZip; xmlIndex++)
int xmlFileIndex = (zipIndex - 1) * xmlFilesPerZip + xmlIndex;
string xmlContent = GenerateXmlContent(xmlFileIndex);
string xmlFileName = $"XMLFile_{xmlFileIndex:D3}.xml";
ZipArchiveEntry entry = zipArchive.CreateEntry(xmlFileName);
using (Stream stream = entry.Open())
using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
writer.Write(xmlContent);
Console.WriteLine("(...50 zip files with a total of 1000 XML files have been generated)");
static string GenerateXmlContent(int id)
Random random = new Random();
int elementCount = random.Next(1, 6);
string name = GenerateRandomString(10);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml($"<?xml version=\"1.0\" encoding=\"utf-8\"?><root id=\"{id:D3}\"><name>{name}</name></root>");
XmlNode root = xmlDoc.SelectSingleNode("/root");
for (int i = 1; i <= elementCount; i++)
XmlElement element = xmlDoc.CreateElement("element");
element.SetAttribute("idx", i.ToString());
element.InnerText = GenerateRandomString(5);
root.AppendChild(element);
static string GenerateRandomString(int length)
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
return new string (Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());