Last active
November 2, 2016 14:42
-
-
Save snobu/44f79fc0b31ff7b4f72b8bd9c55ffe30 to your computer and use it in GitHub Desktop.
IsSubDirectory.cs
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
| // 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