Visual Basic (Declaration) | |
---|---|
Public Shared Function MakeRelativePath( _ ByVal startFile As String, _ ByVal targetFile As String _ ) As String |
C# | |
---|---|
public static string MakeRelativePath( string startFile, string targetFile ) |
Parameters
- startFile
- targetFile
Library/Library.Test/TestFileUtils.cs
C# | Copy Code |
---|---|
Assert.IsNull(FileUtils.MakeRelativePath(null, @"C:\Test\fileb.txt")); Assert.IsNull(FileUtils.MakeRelativePath(@"C:\Test\fileb.txt", null)); Assert.AreEqual( @"filea.txt", FileUtils.MakeRelativePath(@"C:\Test\filea.txt", @"C:\Test\filea.txt") ); Assert.AreEqual( @"fileb.txt", FileUtils.MakeRelativePath(@"C:\Test\filea.txt", @"C:\Test\fileb.txt") ); Assert.AreEqual( @"..\fileb.txt", FileUtils.MakeRelativePath(@"C:\Test\filea.txt\", @"C:\Test\fileb.txt") ); Assert.AreEqual( @"..\fileb.txt\", FileUtils.MakeRelativePath(@"C:\Test\filea.txt\", @"C:\Test\fileb.txt\") ); Assert.AreEqual( @"fileb.txt\", FileUtils.MakeRelativePath(@"C:\Test\filea.txt", @"C:\Test\fileb.txt\") ); Assert.AreEqual( @"sub\fileb.txt", FileUtils.MakeRelativePath(@"C:\Test\filea.txt", @"C:\Test\sub\fileb.txt") ); Assert.AreEqual( @"..\fileb.txt", FileUtils.MakeRelativePath(@"C:\Test\sub\filea.txt", @"C:\Test\fileb.txt") ); Assert.AreEqual( @"C:\Test\sub\fileb.txt", FileUtils.MakeRelativePath(@"E:\Test\sub\filea.txt", @"C:\Test\sub\fileb.txt") ); Assert.AreEqual( @"..\test\fileb.txt", FileUtils.MakeRelativePath(@"sub\filea.txt", @"test\fileb.txt") ); Assert.AreEqual( @"..\..\test\fileb.txt", FileUtils.MakeRelativePath(@"..\sub\filea.txt", @"test\fileb.txt") ); Assert.AreEqual( @"fileb.txt", FileUtils.MakeRelativePath(@"sub\", @"sub\fileb.txt") ); Assert.AreEqual( @"sub\fileb.txt", FileUtils.MakeRelativePath(@"sub", @"sub\fileb.txt") ); Assert.AreEqual( @"sub\fileb.txt", FileUtils.MakeRelativePath(@".\sub", @"sub\fileb.txt") ); Assert.AreEqual( @"..\sub\fileb.txt", FileUtils.MakeRelativePath(@"sub\test", @".\sub\.\..\sub\fileb.txt") ); |
VB.NET | Copy Code |
---|---|
Assert.IsNull(FileUtils.MakeRelativePath(Nothing, "C:\Test\fileb.txt")) Assert.IsNull(FileUtils.MakeRelativePath("C:\Test\fileb.txt", Nothing)) Assert.AreEqual("filea.txt", FileUtils.MakeRelativePath("C:\Test\filea.txt", "C:\Test\filea.txt")) Assert.AreEqual("fileb.txt", FileUtils.MakeRelativePath("C:\Test\filea.txt", "C:\Test\fileb.txt")) Assert.AreEqual("..\fileb.txt", FileUtils.MakeRelativePath("C:\Test\filea.txt\", "C:\Test\fileb.txt")) Assert.AreEqual("..\fileb.txt\", FileUtils.MakeRelativePath("C:\Test\filea.txt\", "C:\Test\fileb.txt\")) Assert.AreEqual("fileb.txt\", FileUtils.MakeRelativePath("C:\Test\filea.txt", "C:\Test\fileb.txt\")) Assert.AreEqual("sub\fileb.txt", FileUtils.MakeRelativePath("C:\Test\filea.txt", "C:\Test\sub\fileb.txt")) Assert.AreEqual("..\fileb.txt", FileUtils.MakeRelativePath("C:\Test\sub\filea.txt", "C:\Test\fileb.txt")) Assert.AreEqual("C:\Test\sub\fileb.txt", FileUtils.MakeRelativePath("E:\Test\sub\filea.txt", "C:\Test\sub\fileb.txt")) Assert.AreEqual("..\test\fileb.txt", FileUtils.MakeRelativePath("sub\filea.txt", "test\fileb.txt")) Assert.AreEqual("..\..\test\fileb.txt", FileUtils.MakeRelativePath("..\sub\filea.txt", "test\fileb.txt")) Assert.AreEqual("fileb.txt", FileUtils.MakeRelativePath("sub\", "sub\fileb.txt")) Assert.AreEqual("sub\fileb.txt", FileUtils.MakeRelativePath("sub", "sub\fileb.txt")) Assert.AreEqual("sub\fileb.txt", FileUtils.MakeRelativePath(".\sub", "sub\fileb.txt")) Assert.AreEqual("..\sub\fileb.txt", FileUtils.MakeRelativePath("sub\test", ".\sub\.\..\sub\fileb.txt")) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7