[Mono-dev] Incorrect Directory.GetParent behavior

Emery Conrad econrad at vt.edu
Mon Apr 24 12:20:09 EDT 2006

Hi there,

Directory.GetParent should return a DirectoryInfo for *both* full path names
and relative path names. (See
microsoft doc). Here's the issue: currently, mono implements
Directory.GetParent using new DirectoryInfo(Path.GetDirectoryName(path)),
but Path.GetDirectoryName *does not* returns an absolute directory name for
a relative path (it returns the String-based relative path information
contained in the argument). So, when mono calls "new DirectoryInfo(relpath)"
for some relative path, it works UNLESS the Path.GetDirectoryName() has
return String.Emtpy (since this is the required behavior for this function
for a relative path of something in the current directory).

The fix is to make the ctor for DirectoryInfo reset the argument to
Directory.GetCurrentDirectory() when the argument is String.Emtpy. Diff is


Index: mcs/class/corlib/System.IO/DirectoryInfo.cs
--- mcs/class/corlib/System.IO/DirectoryInfo.cs (revision 59817)
+++ mcs/class/corlib/System.IO/DirectoryInfo.cs (working copy)
@@ -51,6 +51,9 @@

                public DirectoryInfo (string path)
+                       if(path == String.Empty)
+                               path = Directory.GetCurrentDirectory();
                        CheckPath (path);

                        FullPath = Path.GetFullPath (path);

Emery Conrad
Department of Mathematics
Virginia Tech
5076 Derring Hall
Blacksburg, VA 24061-0406
(540) 231-3324
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20060424/454a393e/attachment.html 

More information about the Mono-devel-list mailing list