Created
May 25, 2017 20:37
-
-
Save a5ync/a1f8ef87107ee315d3995719fbc46fa8 to your computer and use it in GitHub Desktop.
Build container manifest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContainerManifest | |
{ | |
public ContainerManifest(string rootPath) | |
{ | |
_rootPath = rootPath; | |
Files = new List<string>(); | |
TraverseDirectory(rootPath); | |
} | |
public override string ToString() | |
{ | |
return JsonConvert.SerializeObject(this); | |
} | |
private readonly string _rootPath; | |
private void TraverseDirectory(string path) | |
{ | |
var files = Directory.GetFiles(path); | |
if (files.Length > 0) | |
{ | |
foreach (var file in files) | |
{ | |
var realtivePath = new Uri(_rootPath) | |
.MakeRelativeUri(new Uri(file)); | |
Files.Add( | |
realtivePath | |
.ToString() | |
.Replace('/', Path.DirectorySeparatorChar)); | |
} | |
} | |
var directories = Directory.GetDirectories(path); | |
foreach (var directory in directories) | |
{ | |
TraverseDirectory(directory); | |
} | |
} | |
public List<string> Files { get;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment