I'm trying to create an XML-file from file system (directories, subdirectories, files). In ordinary case it's quite simple: recursively scan directories and simultaneously add new XElement to current root XElement, then newly added folder becomes root XElement and so on...
public static XElement ScanDirectoryRecursive(string rootPath, XElement xRoot) {
var di = new DirectoryInfo(rootPath);
foreach (var dir in di.GetDirectories()) {
var xDir = AddXmlNode(xRoot, dir);
ScanDirectoryRecursive(dir.FullName, xDir);
}
foreach (var file in di.GetFiles()) {
AddXmlNode(xRoot, file);
}
return xRoot;
}
But for some reason I have to divide directories scanning and creating XML-nodes in different threads. First method adds results of scanning (DirectoryInfo or FileInfo objects) to List<>, and the second method reads data from this List<> and adds a corresponding XElement.
The problem is that List<> can contain 1, 2, 3 elements, but not the whole branch, so I can't find a way how to create an XML-tree correctly.
I know that my question is little confusing, sorry.
I can post a code sample that I've written by now, but it's a bit large.
And I don't expect you to write code for me, I just want to know how to organize algorithm in general
No comments:
Post a Comment