[Mono-bugs] [Bug 52735][Nor] New - Path.GetDirectoryName returns wrong value for files in root

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 10 Jan 2004 11:11:10 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by tcabanski@oai.cc.

http://bugzilla.ximian.com/show_bug.cgi?id=52735

--- shadow/52735	2004-01-10 11:11:10.000000000 -0500
+++ shadow/52735.tmp.31179	2004-01-10 11:11:10.000000000 -0500
@@ -0,0 +1,64 @@
+Bug#: 52735
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: Windows XP
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: tcabanski@oai.cc               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Path.GetDirectoryName returns wrong value for files in root
+
+Given the file name c:\foo.txt, GetDirectoryName on Mono return c:.  If 
+you later attempt to combine the result of GetDirectoryName (using 
+Path.Combine) with a file name (or even Path.GetFileName(@"c:\foo.txt")) 
+you get a garbage file name (i.e. c:foo.txt instead of c:\foo.txt).
+
+The Microsoft runtime returns c:\ as I expected and this allows 
+Path.Combine to work properly.  Here's a trivial example console 
+application that demonstrates the problem:
+
+using System;
+using System.IO;
+
+namespace ConsoleApplication1
+{
+	/// <summary>
+	/// Summary description for Class1.
+	/// </summary>
+	class Class1
+	{
+		/// <summary>
+		/// The main entry point for the application.
+		/// </summary>
+		[STAThread]
+		static void Main(string[] args)
+		{
+			Display(@"c:\foo.test");
+			Display(@"c:\bob\foo.test");
+			Display(@"\foo\foo.test");
+			Display(@"foo\foo.test");
+		}
+
+		private static void Display(string fileName)
+		{
+			Console.WriteLine();
+			Console.WriteLine("Raw file name   : {0}", 
+fileName);
+			Console.WriteLine("GetDirectoryName: {0}", 
+Path.GetDirectoryName(fileName));
+			Console.WriteLine("GetFileName     : {0}", 
+Path.GetFileName(fileName));
+			Console.WriteLine("Combining       : {0}", 
+Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileName
+(fileName)));
+		}
+	}
+}