Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created January 8, 2018 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/705fcd25084be1a1c3807933ebeae278 to your computer and use it in GitHub Desktop.
Save guitarrapc/705fcd25084be1a1c3807933ebeae278 to your computer and use it in GitHub Desktop.
void Main()
{
var hoge = new[]
{
"ccc/hoge/Resources/fuga/tyger",
"ghoge/Resources/fuga/tyger",
"zxvzxvcz/Resources/fuga/tyger/hogemoge",
"test/fuga/Resources/fuga/tyger",
"asdfadga/fuga/Resources/fuga/tyger/hogemoge",
};
var concat = hoge.OrderBy(x => x).Select(x =>
{
var index = x.LastIndexOf("Resources", System.StringComparison.InvariantCultureIgnoreCase);
var name = x.Substring(index, x.Length - index).Replace("Resources/", "").Replace("resources/", "");
return new ResourceInfo(x, name);
})
.ToArray();
var duplicates = concat.GroupBy(x => x.Name).Where(x => x.Count() > 1).ToArray();
if (duplicates.Any())
{
var dup = duplicates.SelectMany(x => x.OrderBy(y => y.SubdirectoryCount).Skip(1));
concat.Except(dup).Dump();
}
}
// Define other methods and classes here
private struct ResourceInfo
{
public string Path;
public string Name;
public int SubdirectoryCount;
public ResourceInfo(string path, string name)
{
Path = path;
Name = name;
SubdirectoryCount = Path.Replace("/" + Name, "").Count(y => y == '/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment