foreach (string file in Directory.GetFiles(<directory>, <searchpattern>, SearchOption.AllDirectories)) { Uri uriFile = new Uri(Directory.GetCurrentDirectory()).MakeRelativeUri(new Uri(file)); Console.WriteLine(Path.GetDirectoryName(uriFile.ToString())); }
maandag 3 januari 2011
C# - using the Uri class to find the delta of 2 paths
I've seen a lot of solutions for calculating a delta between 2 paths and only recently found out how simple this is when using the Uri class of the .NET framework. The most important method here is Uri.MakeRelativeUri. The following example finds the path of files relative to the current directory:
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten