Skip to content

Instantly share code, notes, and snippets.

@snobu
Last active November 2, 2016 14:42
Show Gist options
  • Select an option

  • Save snobu/44f79fc0b31ff7b4f72b8bd9c55ffe30 to your computer and use it in GitHub Desktop.

Select an option

Save snobu/44f79fc0b31ff7b4f72b8bd9c55ffe30 to your computer and use it in GitHub Desktop.
IsSubDirectory.cs
// https://github.com/projectkudu/KuduSync.NET/blob/5ff87c07d69ed7ce250267d4657c262c89dd547b/KuduSync.NET/FileSystemHelpers.cs#L80
using System;
using System.IO;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
bool result = IsSubDirectory(args[0], args[1]);
Console.WriteLine($"OS: {Environment.OSVersion}");
Console.WriteLine($"Comparing {args[0]} to {args[1]}");
Console.WriteLine($"IsSubDirectory? -- {result}");
}
public static bool IsSubDirectory(string path1, string path2)
{
if (path1 != null && path2 != null)
{
path1 = Path.GetFullPath(path1);
path2 = Path.GetFullPath(path2);
char separator = Path.DirectorySeparatorChar;
Console.WriteLine($"DirectorySeparatorChar is {separator}");
return path2.StartsWith(path1, StringComparison.OrdinalIgnoreCase);
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment