🎉 增加了相对路径
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using IWshRuntimeLibrary;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -156,5 +157,26 @@ namespace GeekDesk.Util
|
||||
}
|
||||
}
|
||||
|
||||
public static String MakeRelativePath(String fromPath, String toPath)
|
||||
{
|
||||
if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
|
||||
if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
|
||||
|
||||
Uri fromUri = new Uri(fromPath);
|
||||
Uri toUri = new Uri(toPath);
|
||||
|
||||
if (fromUri.Scheme != toUri.Scheme) { return toPath; } // path can't be made relative.
|
||||
|
||||
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
|
||||
String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
|
||||
|
||||
if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user