Directory ResolveDirectory(Directory directory, IEnumerable<string> children)
{
if (!children.Any())
return directory;
string childName = children.First();
Directory info = directory.GetDirectories()
.Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
.SingleOrDefault();
if (info != null)
{
return ResolveDirectory(info, children.Skip(1));
}
File file = directory.GetFiles()
.Where(x => string.Compare(x.Name.GetName(), childName, true) == 0)
.SingleOrDefault();
if (file == null)
throw new InvalidOperationException("Could not get directory: " + childName);
if (Path.GetExtension(file.Name.GetName()) == ".zip")
{
var zipFileDirectory = new ZipFileDirectory(file.Name.Name);
return ResolveDirectory(zipFileDirectory, children.Skip(1));
}
throw new InvalidOperationException("Could not resolve the rest of the path: " + childName);
}